Click here to Skip to main content
14,599,201 members
Rate this:
Please Sign up or sign in to vote.
See more:
How can I add something like msgbox in a form if close button is pressed? I mean that if the close button is pressed then a dialog appears with different choices.
Malli_S 20-Sep-12 8:14am
What kind of choices? Which close button you're talking about? 'X' close button or a button you provided with 'Close' text on dialog?
[no name] 20-Sep-12 8:24am
Have a look at the events. The form closing event might be just the thing you are looking for.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Try below code:
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing     
       If (MessageBox.Show("Close?", "", MessageBoxButtons.YesNo) =  Windows.Forms.DialogResult.No) Then
         e.Cancel = True     
End If
End Sub

See following link for more information:[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100