you can use a boolean (global variable) as an exit flag in LoginForm
initialize it:
exit = true;//in constructor
set to false before closing:
frmHome frm = new frmHome(); frm.Show(); exit = false; this.Close();
and in form_closed :
if(exit) Application.Exit();
if the user closes the form using the 'X' button, exit will be true and Application.Exit() will be called.
EDIT:
the above does not work because LoginForm is your main form used by Application.Run(loginForm) .
2 offers:
With exit flag:
replace
Application.Run(new LoginForm())
by
LoginForm loginFrm = new LoginForm(); loginFrm.Show(); Application.Run();
Without exit flag:
replace in current code:
frmHome frm = new frmHome(); frm.Show(); this.Close();
by
frmHome frm = new frmHome(); this.Visible = false; frm.ShowDialog(); this.Close();
manji source share