I would like to find the way to exit my app by Exit command button or by an X in the upper-right corner of the Forms.
I did try to call this:
Code:
Public Function ExitApplication() As Boolean
If MessageBox.Show("Are you sure you want to exit?", "Exit?", _
MessageBoxButtons.YesNo, MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button2) = DialogResult.Yes Then
Return True
Else
Return False
End If
End Function
Code:
If e.CloseReason = CloseReason.UserClosing Or _
e.CloseReason = CloseReason.ApplicationExitCall Then
e.Cancel = Not ExitApplication()
End If
I would like to end my application in one place - I need to do some cleaning, unlocking DB and other stuff.
VB.NET 2008
In VB 6 this did the trick, but VB.NET does not like it:
Code:
Dim frmMyForm As Form
For Each frmMyForm In Forms
Unload frmMyForm
Set frmMyForm = Nothing
Next frmMyForm
Have fun.
---- Andy