If I click on the red X on the upper right hand portion of the window, I am prompted to save an unsaved changes before the app closes.

If I call the following code when I click a button on the screen then the entire app shuts down with no prompting

Application.exit();


I thought the above was supposed to do what I needed. Am I missing something or is there something else I should be using???

Thanks,
Peter

Recommended Answers

All 4 Replies

You could always use the properties tab to remove the microsoft generated form controls and program your own exit, min, max controls. That way you could put your savefiledialog code with your exit button.

Or you could just use the FormClosing event and pop a MessageBox asking the user if he wants to save his work.

If you want to emulate the same functionality as the red x and allow form closing events to work properly use, this.Close();

I got this from http://msdn.microsoft.com/en-us/library/ms157894.aspx
with the following information
The Exit method stops all running message loops on all threads and closes all windows of the application. This method does not necessarily force the application to exit. The Exit method is typically called from within a message loop, and forces Run to return. To exit a message loop for the current thread only, call ExitThread.

Exit raises the following events and performs the associated conditional actions:

*

A FormClosing event is raised for every form represented by the OpenForms property. This event can be canceled by setting the Cancel property of their FormClosingEventArgs parameter to true.
*

If one of more of the handlers cancels the event, then Exit returns without further action. Otherwise, a FormClosed event is raised for every open form, then all running message loops and forms are closed.

Note:

The Exit method does not raise the Closed and Closing events, which are obsolete as of .NET Framework 2.0.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.