1 Replies - 948 Views - Last Post: 01 May 2012 - 06:40 PM Rate Topic: -----

#1 derekvw   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 28-April 12

Custom Exit Warning

Posted 01 May 2012 - 05:50 PM

I know you can use a messagebox to warn users when they are about to exit the application. What I would like to do is open up a new form that gives a yes, no, or view high score option...

What I'm having difficulty with is being able to close the main form and the custom exit form at the same time. In order to open up the custom form when I pressed the "x" on the form, I had to do an e.cancel which apparently is ensuring that I can't use Application.exit().

How can I get the entire application to close when I press "Yes" to close the application on the custom exit.

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Custom Exit Warning

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Custom Exit Warning

Posted 01 May 2012 - 06:40 PM

Use a DialogResult from your form or messagebox,
then take action based on the DialogResult returned.

Your main form is already closing so you don't have to worry about doing anything for that. Just put in your custom box as part of the form.closing event.

void Form1_Closing(object sender, eventargs e)
{
   DialogResult dr = MessageBox.Show("Do you want to see the high score    before closing?");
   if (dr == DialogResult.Yes) ShowHighScoreMethod();
}


This is very common. You see it for things like unsaved documents.

void Form1_Closing(object sender, eventargs e)
{
   if (IsDirty)
   {
      DialogResult dr = MessageBox.Show("Do you want to save your changes before closing?");
      if (dr == DialogResult.Yes) SaveDocument();
   }
}

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1