The construct seemed straightforward to begin with, but . . .
So when the user exits the application, then that is the time to write to a preferences file or do some cleanups etc. Pretty basic stuff I thought.
It’s easy enough to determine if changes have been made, but I can’t work out how to go back, or resume if the user chooses CANCEL. The program exits anyway without my control.
This all happens in the Main Window, Close Event:
Dim result as Integer
Dim myMessage As String = "Do you want to Save the changes made in the SPECIFICATIONS panel?"
result = MsgBox (myMessage,51,"Impulse Recorder")
If result = 6 Then //YES Pressed
HeaderFileWRITE // Write changes to Header Data File
End If
If result = 7 Then //NO Pressed
// Do nothing and exit without saving changes
End If
If result = 2 Then //CANCEL Pressed
Return // Return to the program and do nothing
End If
Intuitively I think it’s something to do the the “close” event - but I cannot see an alternative.
You have to understand the CancelClose Event as a question. Like “Do you want the Window to really Close at it’s current state or do you want to Cancel this Close Event?”
F.e. you can ask your User in the CancelClose event the “Do you want to Save ‘Cancel, Yes, No’” Question and Return from CancelClose a “True” if you want to cancel the Close or a “False” if you want to let the Window close.