perform actions when form closes

How to run code when user closes application in VB.net

Goal: This code shows you how you can run some code when the user closes the form. Below a file is deleted when you close the application. The code is useful for some cleanup at application exit. You can also cancel the closing with "e.Cancel = True".

Instructions: Open a new Windows Forms Application. Replace all the automatically generated code in your project with the code below.