In a windows form project in C#/.net/Visual Studio 2010, if someone hits the close window button, I want to disable some other things in the program as a consequence. Is there a method call for hitting “X” that I can extend?
In a windows form project in C#/.net/Visual Studio 2010, if someone hits the close
Share
The two events that you should use are
FormClosingandFormClosed.In the .Net Framework verion 2.0 these events replaced the obsolete
ClosingandClosedevents.The reason for the new events was that the old ones were not raised when the
Application.Exitmethod was called.An example of the usage of the
FormClosingevent is below:That code simply asks the user if they want to close the form, and if No is selected, it then cancels the event. You can put any logic you require in the event handler.
The MSDN article on
Form.Closingis here and includes references about why the event was made obsolete. The reference forForm.FormClosingis here