Closing Forms

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

All,

I have an application that starts by displaying a logon
form to the user. If they enter the correct information
another form is to be displayed and the logon form closed.

The problem I have is in closing the logon form. If I use
the close method

frmLogOn.Close()

the entire program terminates. I can set the visible
property to false which removes it from the screen but it
is still loaded. How do I close the logon form without
terminating the application. Thanks for the help!

Dan
 
Your setting the logon form as the Main Form of the application. When this
form closes it shuts down the application.

static void Main()
{
Application.Run(new LogonForm());
}

Use the ApplicationContext overload of Application.Run or set the Main Form
properly. Or you could show the logon form prior to calling Application.Run;

static void Main()
{
Form logon = new LogonForm();
if (logon.ShowDialog() == DialogResult.OK) // let them in
Application.Run(new MainForm());
}

HTH;
-Eric
 
Back
Top