打开2个窗口
第一个窗口上有一个Button
第二个窗口上有一个TextBox
按第一个窗口上的Button 把一串字符传到第二个窗口上的TextBox一前是用STATIC 但是不好
用委托怎么实现呢?

解决方案 »

  1.   

    /********************** Form1:一个lable,一个button  ****************/
    private void button1_Click(object sender, System.EventArgs e)
    {
    Form2 f2 = new Form2();
    f2.ReturnValue += new WindowsApplication32.Form2.ReturnEvenHandler(f2_ReturnValue);
    f2.ShowDialog();
    } private void f2_ReturnValue(string str)
    {
    this.label1.Text = str;
    }
    /******************** Form2:一个TextBox,一个button ***********************/
    public delegate void ReturnEvenHandler(string str);
    public event ReturnEvenHandler ReturnValue;
    private void button1_Click(object sender, System.EventArgs e)
    {
    if(ReturnValue != null)
    ReturnValue(this.textBox1.Text);
    }
      

  2.   

    这种情况用委托没什么意义.不如在Form2里写个属性:
            public string TextboxText
            {
                get{ return this.textBox1.Text;}
                set{ this.textBox1.Text = value;}
            }
    在Form1 中直接操作该属性
      

  3.   

    我是想调用Form2里的方法来修改TextBox里的值
    请问怎么做