Pass a value from login form to main form

后端 未结 4 2085
礼貌的吻别
礼貌的吻别 2021-01-26 09:26

I have a login screen and I need to pass username to my main form (for getting permissions etc.). Here is my code:

//Login
private void button1_Click(object send         


        
4条回答
  •  再見小時候
    2021-01-26 10:06

    1. This is the best way to transfer data from one form to another, On the LoginForm.cs write like this:

      ex.UserName = txtUserName.text;    
      Password=txtPassword.text;    
      MainForm mainForm = new MainForm(UserName,Password);    
      this.Hide(); 
      
      mainForm.Show();
      
    2. In the MainForm.cs edit the

      public MainForm () { }

    like this:

    public MainForm(string userName,string password){
    }
    

提交回复
热议问题