我很菜,如题,form1.textbox1.Text=form2.textbox1.Text行吗???

解决方案 »

  1.   

    不可以的,你定一个PUBLIC的变量吧
      

  2.   

    窗体之间传值,可以用构造函数。窗体Fr_zspzd:
    private void button7_Click(object sender, System.EventArgs e)
    {
    Fr_zspzd zspzd=new Fr_zspzd(this.dataSet11,this.myToolbar1);
    zspzd.Show();
    }窗体Fr_zspzd:
    public class Fr_zspzd : System.Windows.Forms.Form
    {
    DataSet ds1=null;
    myBaseForm.myToolbar myToolbar1;
                      ...........
              public Fr_zspzd(DataSet ds,myBaseForm.myToolbar myToolbar)  //构造函数
    {
    ds1=ds;
    myToolbar1=myToolbar;   //把传递的信息保存下来
                                ........
                       }
              private void Fr_zspzd_Load(object sender, System.EventArgs e)
    {
                                //函数中就可以使用了
                                //传递的值是和第一个页面是同步的
                       }也可以用属性传:
    private void button5_Click(object sender, System.EventArgs e)
    {
    WindowsApplication1.Form2 f2 = new Form2();
    f2.MdiParent=this;
    f2.Show();
    }//-----------------------------------------------
    public class Form2 : System.Windows.Forms.Form
    {
    private Form1 fm1;
    public Form1 Fm1
    {
    get{return fm1;}
    set{fm1=value;}
    }
      

  3.   

    把Form1 和Form2 类放到同一个名空间中, 需要传递的数据 申明为pubilic 或者使用 property,申明为public,就可引用了
      

  4.   

    Form2的textBox的Modifiers属性设置为Public就可以在Form1中访问了
      

  5.   

    在frm1中:
    public class frm1 : System.Windows.Forms.Form
    {
       string 要传的分 = "分";
       public string _要传的分
       {
          get
          {
             return 要传的分;
          }
       }
    }在frm2中:frm1 frm = new frm1();
    string 接受分;
    接分=frm._要传的分;
      

  6.   

    Of courseYou may change the modifier of your button from private to public in source code, or change it by properties explorer.( There is a Modifiers property in properties explorer. In Design group.)Then you can use "form1.textbox1.Text=form2.textbox1.Text" (Both the modifier of the textbox1 of form1 and form2 are public)
      

  7.   

    //Form1private void button1_Click(object sender, System.EventArgs e)
    {
        Form2 frm2 = new Form2(this);
        frm2.Show();
    }

    public string TEXTBOX1
    {
        set
        {
            textBox1.Text = value;
        }
    }
    //Form2
    public Form2(Form1 frm1) : this()
    {
        this.frm1 = frm1;
    }
    private void button1_Click(object sender, System.EventArgs e)
    {
        System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
        System.Type t = a.GetType("MyNamespace.Form1", false); 

        System.Reflection.PropertyInfo pi = t.GetProperty("TEXTBOX1");
        pi.SetValue(frm1, this.textBox1.Text, null);
    }