In my project, there are two forms frmLogin
and frmMain
. After successful login from frmLogin
I am showing the frmMain
form to the user by doing something like this:
In frmLogin
form button_click
event:
frmMain main = new frmMain();
main.Show();
this.Hide();
In frmMain
when the user logs out I want to show the same frmLogin
form (not the instance). How to do this?
I tried this code: (creating another instance of frmLogin
which I don't want)
In frmMain
form button_click
event:
if (MessageBox.Show("Do you really want to log out?", "Alert", MessageBoxButtons.YesNo).Equals(DialogResult.Yes))
{
this.FormClosing -= frmMain_FormClosing;
//
Process p = new Process();
p.StartInfo.FileName = Application.ExecutablePath;
p.Start();
//
this.Dispose();
}
I have also tried using internal
specifier but no use.
EDIT: As a trainee, I am not allowed to use Static
keyword and altering program.cs
. If the above approach requires restricted methods (which I have mentioned) then please suggest me an alternate approach.