Reputation: 353
I have a problem with my application, I want to make a simple login page which send you trough a home page (login success), so I put this code on my program.cs that I could navigate trough forms :
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 a = new Form1();
a.Show();
Application.Run();
}
}
the probleme is that if I close my app (login page) before submitting, the app doesn't close...
Thanks
Upvotes: 0
Views: 110
Reputation: 1615
I myself use this solution:
I use:
public static Form1 a = null;
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
a = new Form1();
Application.Run(a);
}
and when the sign in button clicked, after the authentication process, I use:
this.Hide();
Form2 form = new Form2();
form.Show();
And when I want to sign out, I use:
this.Close();
Program.a.Show();
And when I want to close the application, I use:
Program.a.Close();
Upvotes: 0
Reputation: 1105
Usually you should start your application like this:
Application.Run(a);
Alternatively you can execute the following in the FormClosed event of your form:
Application.Exit();
Upvotes: 0