How to process the Cancel button in a MessageDialog?

I have a MessageDialog loaded in my window Closing event. This has Save as the ActionButton, Don’t Save as the AlternateActionButton and a Cancel button. Save triggers a save to disk, Don’t Save does nothing (and the window, and the application, closes). These are working as expected. I would like the Cancel button to dismiss the MessageDialog and allow the user to continue with the program, but I cannot see how to do this. Instead it closes the window and the application (just like the AlternateActionButton).

Is there a way to cancel the window closing event?

Thanks,

Ian.

// Window.CancelClose

Var Dialog As New MessageDialog
// Do all your setup

Var Choice As MessageDialogButton = Dialog.ShowModal(Self)
Select Case Choice
Case Dialog.ActionButton
  // Save
Case Dialog.AlternateActionButton
  // Don't Save
Else
  // Cancel or closed
  Return True
End Select

You could skip assigning the button to a variable of course, but this makes it easier to see in the debugger and I think looks cleaner.

Edit: I could have saved myself a little time and just linked to the docs: MessageDialog — Xojo documentation

What you’re looking for is the CancelClosing event rather than the Closing event.

This allows you to stop the window from closing by returning True.

Thanks for the responses. That is what I was looking for.