Var MesDia As New MessageDialog
Var MesDiaButton As MessageDialogButton
MesDia.Icon = MessageDialog.GraphicCaution
MesDia.ActionButton.Caption = "Save"
MesDia.CancelButton.Visible = True
MesDia.AlternateActionButton.Visible = True
MesDia.AlternateActionButton.Caption = "Don't Save"
MesDia.Message = "Do you want to save changes to this document before closing?"
MesDia.Explanation = "If you don't save, your changes will be lost. "
MesDiaButton = MesDia.ShowModal
Select Case MesDiaButton
Case MesDia.ActionButton
MainWindow.SaveDocument()
Case MesDia.AlternateActionButton
// user pressed Don't Save
Case MesDia.CancelButton
// user pressed Cancel
End Select
What is problem in this code?
This code is not saving data when save is click.
What can be the code for Don’t Save and cancel.
Does your app only support one window at a time? If not you are going to have a problem with MainWindow.SaveDocument, it should be Self.SaveDocument(), or even just SaveDocument(). Within the window you can refer to “this window” as Self.
You also should not put this in the Closing event. It should be in the CancelClose event. The job of the Close event is to tidy up as the window closes. For example freeing up any objects that may be required. In CancelClose you can return True in order to prevent the window from closing, which is what you are going to need for CancelButton.
As a general principal you should turn off ImplicitInstance and manage your windows. About the only time you should use it is if you are building an app that only every has one window. Outside of the class you can find the frontmost window via App.Window(0)