Variation of the (x) button - VB.NET
You know the (x) button on the toolbar of your app? I want to add a piece of code right after the it开发者_开发技巧 closes the window. How would I do this?
You need to add a handler to the FormClosing event. Looking at the CloseReason property of the received FormClosingEventArgs you will know if the form is closing because the user explicitly closed the window or for any other reason.
EDIT: FormClosing will fire before the window is actually closed, and you can cancel this event so that the window is not actually closed. FormClosed, mentioned by Jon, will fire after the window is closed.
Attach an event handler to the Form.FormClosed
event.
精彩评论