You have already answered half of the problem yourself. You know when you are in a locked session versus the initial login. If you create a custom login form you can program any logic into that you would like....including calling some shared method within your application or your main MDI form to shutdown the forms and save changes. Better yet, create a shared propety that has a direct object reference to the main form and expose a method to call.
Public NotInheritable Class MyApplication
Private Shared _MainForm As System.Windows.Forms.Form
Public Shared ReadOnly Property MainForm As System.Windows.Forms.Form
Get
Return _MainForm
End Get
End Property
End Class
Set this reference to the class when the main form loads or instantiates:
MyApplication.MainForm = Me
Next, create a method within the main form to shut down your children forms as shown in a previous post:
Public Sub ShutDownFormsAndApp()
'-- Place code here to close forms
'-- Terminate the app
End
End Sub
Now, in the custom login form, you can access the shared property to close the forms and shutdown the app. Just add a button to your login form if you would like and enable it only for a locked session. In the click call the shared property and public method:
CType(MyApplication.MainForm, MyMainForm).ShutDownFormsAndApp()