Form Closing

It is a common case that you would want to write code that is executed when the form closes. The Closed Event is sent to a form after the form is closed, and the form can handle this event if it has an OnClosed method. The OnClosed method is automatically called on a form if a Closed Event is fired for that form.

Here is a sample OnClosed method that shows where you would put your application logic, which is executed when the form is closed:

Protected Overrides Sub OnClosed(ByVal e As System.EventArgs)
    MyBase.OnClosed
    'Add code here
End Sub

After this method is called, the form is about to be closed, and there is no turning back. What if you wanted to write code to validate the form before it was closed? And, if the form is not ...

Get Visual Basic® .NET by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.