Form Closing event

  • Thread starter Thread starter Trevor
  • Start date Start date
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.
 
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.
 
Back
Top