-
form unload
I put this code to the Closed() event of a Form in VB.NET.
If MessageBox.Show("Would you like to exit?", "Exit", MessageBoxButtons.OKCancel) = DialogResult.OK Then
Application.Exit()
Else
Cancel = 1
End If
All I want to happen is, when I click the Close Button(X) of the Form, the messagebox OK/Cancel will show and asking if you want to exit or not. If you click OK button, the form will unload. But if you click the Cancel button the Form will not unload. I tried the Cancel = 1 but it doesn’t work. Any solution for this problem.
-
Soemthing like this should work....
Code:
Private Sub Form1_Closing(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If MessageBox.Show("Really?", "", MessageBoxButtons.OKCancel) = DialogResult.OK Then
Application.Exit()
Else
e.Cancel = True
End If
End Sub
If this is a subform and you dont want to end the application replace Application.Exit() wit Me.Dispose()
-