在form1中textbox1的内容希望在form2打开时,form2中的textbox1能够直接显示form1中textbox1的内容。这个要怎么实现?我是菜鸟,希望各位大虾详细指出,谢谢。

解决方案 »

  1.   

    Form1增加一个属性:public string TextBoxText
    {
        get { return this.textBox1.Text; }
    }Form2中添加字段和构造函数:private Form1 form;
    public Form2(Form1 f): this()
    {
        this.form = f;
        this.textBox1.Text = f.TextBoxText;
    }弹窗:Form2 f = new Form2(this);
    f.ShowDialog();
      

  2.   

    看看这个
    http://blog.csdn.net/yunhaiC/archive/2011/05/31/6456767.aspx
      

  3.   


    重载Form2窗体构造函数
    public Class Form2
    {
      public Form1 fr;
       public Form2(Form1 fr,string s)
       {
          this.fr = fr;
          TextBox1.Text = s;   
       }
    }public Class Form1
    {
        public Form1(){}    public void Button1_Click(object sender,EventArgs e)
        {
              //通过按钮点击,实例化一个Form2对象,传入的是当前Form1窗体队对象this,及Form1中的TextBox1的内容
              Form2  fr2 = new Form2(this,TextBox1.Text);
              fr2.Show();
        }
    }
      

  4.   

    Form2 form2=new Form2(textbox1.text)
    form2.show();public Form2(string str)
    {
       InitializeComponent();
       textbox2.text=str;
    }
      

  5.   

    http://topic.csdn.net/u/20110407/19/c1068d69-7331-4d02-bc0b-f5ba7a5f8dd8.html
    和继承没有关系。