Form Closing event

T

Trevor

I need to display a confirmation message box when the user tries to exit the
main form of my application. I placed code in the MainForm_Closing event to
handle this and it works as expected. Now I show a modal LoginForm in
MainForm_Load using ShowDialog(). If the user clicks cancel on the
LoginForm then I want to close the MainForm, but I don't want to ask the
user if he wants to exit. What is the best way to do this? Is there some
way of detecting what originated the Closing event? I only want to display
the message box if the user clicked the "X" and not if I call
MainForm.Close. I hope this makes sense.
 
N

Nicholas Paldino [.NET/C# MVP]

Trevor,

Instead of bringing up the new form in the load event of the form main
form, I would run two application loops (calls to the static Run method on
the Application class). The first would be for your login form. If the
login succeeded, then I would then show your main form (if not, you would
exit your program).

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top