How to Implement login form and main form without more instances in c#

后端 未结 1 1697
忘掉有多难
忘掉有多难 2021-01-16 08:13

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 ((txtU         


        
相关标签:
1条回答
  • 2021-01-16 08:58

    You need to put your login part in Program.cs , before Application.Run() called e.g :

     if (new frmLogin().ShowDialog() == DialogResult.OK)
     {
         Application.Run(new frmMain());
     }
    

    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 :

    if (txtUserName.Text == "blah"
          && txtPassword.Text == "blah")
       {
         txtPassword.BackColor = Color.YellowGreen;
         txtUserName.BackColor = Color.YellowGreen;
         this.DialogResult = DialogResult.OK;
       }
       else
       {
         txtPassword.BackColor = Color.Salmon;
         txtUserName.BackColor = Color.Salmon;
        }
    
    0 讨论(0)
提交回复
热议问题