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.