Form.FormClosing Event occurs Occurs before the form is closed.
The FormClosing event occurs as the form is being closed. When a form is closed, it is disposed, releasing all resources associated with the form. If you cancel this event, the form remains opened. To cancel the closure of a form, set the Cancel
property of the FormClosingEventArgs
passed to your event handler to true
.
When a form is displayed as a modal dialog box, clicking the Close button (the button with an X at the upper-right corner of the form) causes the form to be hidden and the DialogResult property to be set to DialogResult.Cancel
. You can override the value assigned to the DialogResult property when the user clicks the Close button by setting the DialogResult property in an event handler for the FormClosing event of the form.
Note: The Closing
event became obsolete in the .NET Framework version 2.0; so we use the FormClosing
event instead.
Find the full documentation here.