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.