1. frmHome frm = new frmHome();
frm.Show();
this.Close();
I\'m opening HomeForm from LoginForm. In LoginForm
All you need to do is this it closes the 2 forms without problem. Form1 fin = new Form1(); fin.Close(); this.Visible = false; Form2 win = new Form2(); win.Visible = true;
you can use a boolean (global variable) as exit flag in LoginForm
initialize it to :
exit = true;//in constructor
set it to false before closing:
frmHome frm = new frmHome();
frm.Show();
exit = false;
this.Close();
and in form_closed:
if(exit) Application.Exit();
if a user closes the form with the 'X' button, exit will have the value true, and Application.Exit() will be called.
the above is not working because LoginForm is your main form used by Application.Run(loginForm).
2 suggestions:
With exit flag:
replace
Application.Run(new LoginForm())
by
LoginForm loginFrm = new LoginForm();
loginFrm.Show();
Application.Run();
Without exit flag:
replace in your current code:
frmHome frm = new frmHome();
frm.Show();
this.Close();
by
frmHome frm = new frmHome();
this.Visible = false;
frm.ShowDialog();
this.Close();