怎么把Form1中的控件变量user.Text的值在Form2中也能调用,最好简单点,谢谢!!!

解决方案 »

  1.   

    ((Form1)Application.OpenForms["Form1"]).user.Text
      

  2.   

    不行啊,出这问题错误 1 “WindowsFormsApplication2.Form1.mima”不可访问,因为它受保护级别限制 d:\users\administrator\documents\visual studio 2010\projects\WindowsFormsApplication2\WindowsFormsApplication2\Form2.cs 28 155 WindowsFormsApplication2
    SqlCommand cmd = new SqlCommand("select Sname,Sex,Sage,Sadress from dbo.UserMessage where password='"+   +"'", con); 我的代码是这样的,怎么才能在这添加‘”+  +“’form1中的User.Text控件值
      

  3.   

    //窗体1
     public string txt1;
            private void Form1_Load(object sender, EventArgs e)
            {            txt1 = textBox1.Text;
             }//窗体二
    private void Form2_Load(object sender, EventArgs e)
            {
                Form1 f1 = new Form1();
                string getF1 = f1.txt1;
             }
      

  4.   

    user控件中有一个参数你可以设置成PUBLIC
     这样就可以了
      

  5.   

    有好几种方法,在这里只说一个:
    在Form2中声明一个String类型的变量strText, 然后在Form1接受user.Text;就是在Form2 frm2=new Form2()位置添加一句话:
         frm2.strText=user.Text;
    然后就可以使用strText变量了,和user.Text值一样的!