The List Manager Project: When to Ask User if he wants to save


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 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

The X in the corner was clicked:

    Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
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
See the complete code at this point.
INDEX, Introduction, Build the Menu, Add items to a listbox, Delete items from the listbox, Save: Write the contents of the list box to a file, Open File: Read file and add to list box, Ask the user if he wants to save, When to ask the user if he wants to save, The User closes the program
Next lesson: List Manager application Finishing Touches

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

The User closes the program