The (X) Box on Forms

Dcurvez

Member
Joined
Apr 8, 2010
Messages
18
Programming Experience
Beginner
hi all..

i am wondering how and where to go to get a confirmation box to open before you close the window with the (X) button on the form (top right)
I am new at all of this and so really am having trouble with this. everytime i hit the close button in debug on my form..the form just closes. I want to have a yes no box that comes up before closing.

In my created menu..under File..i have an exit option and it has a box to confirm, now i want one for the (X)Close button?
 
Use the FormClosing event:


VB.NET:
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
		 If MessageBox.Show("Are you sure you want to exit?", "Exiting", _
		      MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No Then
	                 e.Cancel = True
                 End If
End Sub
 
Back
Top