Zebra0.com

visual-basic listmanager

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.

The user closes the program using the menu item Exit:

Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles mnuExit.Click
  'Exit if there are no changes or the user doesn't want to savr
  Dim okToClose As Boolean = changed
  If changed Then
    okToClose = AskToSave()
  End If
  If okToClose Then
    End
  End If
End Sub

The X in the corner was clicked:

Private Sub Form1_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
  'The usre clicked the X in top right corner, remind to save
  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
See the complete code at this point.

NEXT: Build the Menu