Cancel closing a form
-
Hello gurus, I'd like to know how to cancel the
Closing
event? I mean, when the user click on the close button of the main window, I ask him if he wants to quit via theMessageBox
class. If he answers no or cancel, the window does not close. Can someone show me a code snippet please? Thanks for the help. Best regards. Fred. There is no spoon. -
Hello gurus, I'd like to know how to cancel the
Closing
event? I mean, when the user click on the close button of the main window, I ask him if he wants to quit via theMessageBox
class. If he answers no or cancel, the window does not close. Can someone show me a code snippet please? Thanks for the help. Best regards. Fred. There is no spoon.Cancelling the closing of a form is quite simple and can be implemented as follows: protected void Form1_Cancel (Object sender, CancelEventArgs e) { if (!myDataIsSaved) { e.Cancel = true; MessageBox.Show("You must save first."); } else { e.Cancel = false; MessageBox.Show("Goodbye."); } } Elvis (a.k.a. Azerax) Life is Music listen to it before it fades
-
Cancelling the closing of a form is quite simple and can be implemented as follows: protected void Form1_Cancel (Object sender, CancelEventArgs e) { if (!myDataIsSaved) { e.Cancel = true; MessageBox.Show("You must save first."); } else { e.Cancel = false; MessageBox.Show("Goodbye."); } } Elvis (a.k.a. Azerax) Life is Music listen to it before it fades