父窗口和子窗口各有一个TextBox,在子窗口上点按钮后将子窗口中TextBox的数据传递到父窗口的TextBox中,请教如何实现?
看了http://blog.csdn.net/zhzuo/archive/2004/04/05/22027.aspx后还是不明白,照着上面的操作总是出错,代码应该没写全..

解决方案 »

  1.   

    Form1 f = (Form1)this.Owner; //指向父窗口 假设Form1父窗口类名
    然后可以传值了
         
      

  2.   

     private void button1_Click(object sender, System.EventArgs e)
        {
              Form1 f = (Form1)this.Owner;
              f.textbox1.Text="......";
        }
      

  3.   

    这个实现是有很多方式的,我另外写了另外一篇文章。楼主也可以参考一下,
    窗体的参数传递
    http://blog.csdn.net/zhzuo/archive/2006/05/05/708941.aspx#sec5
      

  4.   

    用属性传很方便
    比如把form2的strName的值传到form1的form1_nameform1中代码Form form2 = new Form2();
    string form1_name = Form2.strName;form2中代码//属性
    private static string form2_name;
    private static string strName
    {
        get
        {
            strName = form2_name;
        }
    }这样,就成功的把form2的变量form2_name的值传到了form1手写的程序,可能有问题,你试一下
    这个方法肯定没问题,出问题了你再问我
      

  5.   

    父窗体:fomFu,文本框:txtFu,按钮:btnFu
    子窗体:fomZi,文本框:txtZi,按钮:btnZi
    btnFu中的单击代码fomZi fomchild=new formZi(this);
    fomchild.Show();子窗体中构造函数代码加一行.public fomFu fomParent;
    class XXX(fomFu nfomParent)
    {
    //略//下面为要加的一行
    fomParent=nfomParent;
    }在父窗体中把txtFu设置为public子窗体这样调用
    fomParent.txtFu.Text=this.txtZi.Text;
      

  6.   

    太感谢楼上的了,才发现关键问题在"在父窗体中把txtFu设置为public "