I have two Win forms in my project, one Login
form, and the Main
form. I have a button in Login
form, which when clicked should open the Main
form and close the current(Login) form.
I have tried this method
private void button1_Click(object sender, EventArgs e)
{
Mainform frm = new Mainform();
frm.Show();
this.Hide();
}
But it only hides the current form. So even after I close the Main form, I have to manually stop debugging by pressing Shift + F5.
Then I have tried this following code
private void button1_Click(object sender, EventArgs e)
{
Mainform frm = new Mainform();
frm.Show();
this.Close();
}
But now, when I click the button, the Mainform
opens and within a second, both the forms are closed, and the program stops debugging.
How do I correctly open Mainform
from Login
form and I don't have to stop debugging ,manually ?