How to perform tasks before the form is closed and how to prevent a form from being closed when the Close button is clicked?
We can listen to the Form’s FormClosing event and in the event handler function, we can run the codes to do what we want. For detailed information, please refer to this MSDN documentation:
FormClosing event occurs before a form is being closed. To cancel the closure of a form, in that form’s FormClosing event handle, we should set the FormClosingEventArgs’s Cancel property to true.
Microsoft is conducting an online survey to understand your opinion of the Msdn Web site. If you choose to participate, the online survey will be presented to you when you leave the Msdn Web site.
Would you like to participate?