How To Get The Forms Closing And Closed Events To Execute When Exiting An Application
Article Information
Language:
IDE:
Framework:
Area:
Audience:
VB.NET
Any
1.x
Windows.Forms (Controls)
Beginner, Intermediate, Expert
The Problem
For some unknown reason (to me at least) when you execute an Application.Exit call in VB.NET 2003 the closing and closed events for any forms in an application are not executed. This article gives one possible way of working around this issue so that on exiting an application all the form closing and closed events are executed.
The Solution
You will need to ensure that your project starts with a Sub Main and not a form. The following code could become your startup module.
Module & Class Code
The following code will need to be added to every form that you want to execute the form closing and closed events on when exiting an application.
Form Code
Note that every form that you want to execute the closing and closed events on should included the above code and be instantiated using Dim oForm as New FormName(True), where FormName is the name of your form.