[dba-VB] OT: C# Question, Exiting Gracefully

Ron Allen chizotz at charter.net
Tue Jun 17 11:53:10 CDT 2003


How do you exit a Windows forms application gracefully?

private void menuItemFileQuit_Click(object sender, 
System.EventArgs e)
      {
	DialogResult myResult;
	myResult = MessageBox.Show("Are you sure you want to quit 
?","Polybags Tracking",MessageBoxButtons.YesNo , 
MessageBoxIcon.Question);
         if (myResult == DialogResult.Yes)
	{
	     this.Close();
	     Application.Exit();
	}
      }

Which works fine when the user plays nice and uses my Quit 
menu item. What I'm having trouble figuring out is how to 
handle when the user clicks on the close 'X' button, or 
uses the control box or alt-F4 to exit the program. I have 
put the Application.Exit(); in the formMain_Unload, 
formMain_Close, etc events and the event never fires. I 
can't find anything about this in the help files, on the 
MS site, or in the two thick books on C# I have. Its 
frustrating, because in VB this is pretty simple to do.

Any help out there?

Thanks,

Ron


More information about the dba-VB mailing list