Stopping Program from Closing?

Started by G_G, October 30, 2009, 05:49:55 pm

Previous topic - Next topic

G_G

Well you know how in notepad or paint or whatever program you go to close it and it asks if you want to save first right?

Well if you click yes, it saves, no it just closes, and cancel which cancels the close. How would I do this?

fugibo

October 30, 2009, 06:26:00 pm #1 Last Edit: October 30, 2009, 06:28:26 pm by Longfellow
I'm guessing you'd use C's signal(<SIGNAL>, <HANDLER>) function, but I could be wrong.

EDIT:
Looks like I was: Linky

Ryex

this is the code I used to stop the RMX-OS GUI from closing and untill it kew if you wanted to run in the task bar


 this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.rmxos_closing);



private void rmxos_closing(object sender, FormClosingEventArgs e)
       {
           if (runingintaskbar == false)
           {
               DialogResult result = MessageBox.Show("Do you want to keep running in the task bar?", "Closing", MessageBoxButtons.YesNo);
               if (result == DialogResult.Yes)
               {
                   e.Cancel = true;
                   minimize_to_tray();
                   
               }
               else
               {
                   if (cfg_saved == false)
                   {
                       DialogResult result2 = MessageBox.Show("The configuration data has not been saved \r\n would you like to save now?", "CFG Not Saved!", MessageBoxButtons.YesNo);
                       if (result2 == DialogResult.Yes)
                       {
                           save_data();
                       }
                   }
                   if (serverRunState == true)
                   {
                       RmxosProcess.Kill();
                   }
               }
           }
           else
           {
               if (cfg_saved == false)
               {
                   DialogResult result2 = MessageBox.Show("The configuration data has not been saved \r\n would you like to save now?", "CFG Not Saved!", MessageBoxButtons.YesNo);
                   if (result2 == DialogResult.Yes)
                   {
                       save_data();
                   }
               }
               if (serverRunState == true)
               {
                   RmxosProcess.Kill();
               }
           }
           
           
       }


"this" being the Form insistence
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

There's an event called FormClosing. Just define a method that is called at that moment and abort it. I can't remember how exactly I did it, but if you still have the Blizz-ABS Config source, I did it in there to make the saving before closing dialog possible.

Ryex beat me to it. >8U

@LF: That's for C in Unix. He's using C# in Windows. -_-
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

fugibo

Quote from: Blizzard on October 30, 2009, 06:33:09 pm
There's an event called FormClosing. Just define a method that is called at that moment and abort it. I can't remember how exactly I did it, but if you still have the Blizz-ABS Config source, I did it in there to make the saving before closing dialog possible.

Ryex beat me to it. >8U

@LF: That's for C in Unix. He's using C# in Windows. -_-


Holy crap, Windows doesn't support signal()?
Holy crap, C# doesn't support C functions?

Blizzard

Windows doesn't have signals. Interrupts are handled in a different way.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Thanks guys! Got it working *lv's up ryex*