We have a function that ask the user if he wants to save. If he says yes we save, then we return to the calling function whether it is ok to clear.
Private Sub mnuExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Dim okToClose As Boolean = Changed
If Changed Then
okToClose = AskToSave()
End If
If okToClose Then
End
End If
End Sub 'mnuExit_Click
Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosingSee the complete code at this point.
Dim closeApp As Boolean
If Changed Then
closeApp = AskToSave()
If closeApp = False Then
e.Cancel = True 'Don't close the app!
End If
End If
End Sub 'Form1_FormClosing