views:

186

answers:

2

Hey guys.

You know the (x) button on the toolbar of your app? I want to add a pice of code right after the it closes the window. How would I do this?

Thanks

+4  A: 

Attach an event handler to the Form.FormClosed event.

Jon Skeet
+4  A: 

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.

Konamiman