Reputation: 1880
I have a game I've written in OpenTK but am looking for a way to add a handler to the close button of the game window without actually closing the game (e.g. invoking a "do you want to save before you quit?" sort of dialog). I can't seem to find any event handler or documentation that accomplishes this.
Upvotes: 1
Views: 768
Reputation: 8243
You can override the OnClosing
method and show your message box there. If the user does not want to close, you can use e.Cancel = true
, which will stop the form from closing:
protected override void OnClosing(CancelEventArgs e)
{
// ... show message box
if (/* wants to save*/)
{
// Cancel closing, the player does not want to exist
e.Cancel = true;
}
base.OnClosing(e);
}
Upvotes: 1