lab12
lab12

Reputation: 6448

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?

Upvotes: 1

Views: 621

Answers (2)

Konamiman
Konamiman

Reputation: 50273

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.

Upvotes: 5

Jon Skeet
Jon Skeet

Reputation: 1500665

Attach an event handler to the Form.FormClosed event.

Upvotes: 4

Related Questions