Try something else like this:
this.Hide(); Main.ShowDialog(); this.Close();
You want to hide the login form before you open the dialog box, and then close the login form after closing the dialog.
Simply closing the Login dialog box will eventually end the application, so this is not a real solution, but you still want to hide the login.
Simply put, put things in the order you want them to go in, especially when working with message loops.
First you hide the login form.
You will then see the “Basic Form” dialog, but do not let the caller “ShowDialog ()" continue until the dialog closes.
Finally, once the dialog is closed, you close the login form, ending the application.
David Morton
source share