Iam creating an instance to the main form on login button click and again creating instance to login form on logout button click. my code is
if ((txtUsrNm.Text == "Admin") && (txtPswd.Text == "Admin"))
{
mainForm mainFm = new mainForm();
mainFm.userNam = txtUsrNm.Text;
mainFm.pasWrd = txtPswd.Text;
mainFm.Show();
this.Hide();
}
else
{
MessageBox.Show("Invalid Username or Password.");
}
and again in logout button
this.Hide();
loginFrm lgn = new loginFrm();
lgn.Show();
If I try to close instead of Hide, the whole application is closing.
By doing this Application.OpenForms count is increasing on every login and logout operations. How to implement the login and logout operations in windows application. Is there any other Idea for Implementing this operation. Thanking you
You need to put your login part in Program.cs , before Application.Run() called
e.g :
then put login codes in login form. after user logged in, form login will be closed and will set this.dialogresualt = dialogresult.ok;
e.g :