MDI父窗体f1上面有个button.点击button   ShowDialog f2子窗体
点击f2子窗体上的button,f2关闭的同时把f2的值传到f1上去,怎么办
最好有代码

解决方案 »

  1.   

    很多办法
    比如在父窗体上建一个静态变量,假设你传回的是string类型
    public static string aaa;在f2的button事件中写
    f1.aaa = "返回值";
      

  2.   

    在f2中:f1 form;
    在f1的button事件中:
    f2 ff=new f2();
    f2.form=this;
    ff.showdialog(this);f2的button事件中:
    form.控件名=要传的值;
    this.close();
      

  3.   

    又或者你在子窗体上建一个变量存储返回值
    public sting aaa;
    在点击事件中给aaa赋值
    aaa = "返回值";在父窗体创建子窗体的时候这么写
    private string aaa;
    f2 newMDIChild_1 = new f2();
    newMDIChild_1.MdiParent = this;
    newMDIChild_1.Show();
    this.aaa = newMDIChild_1.aaa;
      

  4.   

    f1中增加个属性
    private string str = string.Empty;
    public string MyProperty
    {
    set
    {
    str = value;
    }
    get
    {
    return str;
    }
    }f1的按钮点击事件,
    f2   ff=new   f2();
    ff.showdialog(this); f2的按钮点击事件中
    this.Owner.MyProperty = "test";
    this.Close();属性的类型可以根据自己的需要更换。
      

  5.   

    申明一个Object对象作为参数传过去,C#中所有Object对象都是引用类型,如你传个button或者DATASET之类的变量过去,在对应的界面定义变量,然后把传过去的对象给他就行了如果全的是值类型,可以定义Public类型,在主界面上直接访问,如果子界面已经关闭,可以考虑写Object类,把你的值类型(string,struct)放在类中,然后传回Object类
      

  6.   

    我是这样写的
    f1:
    public string str = null;
    private void button1_Click(object sender, EventArgs e)
            {
                if (checkBox1.Checked == true)
                {
                    frmCustomerinfo customer = new frmCustomerinfo();
                    customer.FormClosing += new FormClosingEventHandler(customer_FormClosing);
                    customer.ShowDialog();
                }
            }        void customer_FormClosing(object sender, FormClosingEventArgs e)
            {
                MessageBox.Show(str);
            }f2:
    private void button2_Click(object sender, EventArgs e)
            {
                frmInfo info = new frmInfo();
                info.str = "员工";
                MessageBox.Show(info.str);
                this.Close();
            }
      

  7.   

    申明一个Object对象作为参数传过去,C#中所有Object对象都是引用类型,如你传个button或者DATASET之类的变量过去,在对应的界面定义变量,然后把传过去的对象给他就行了
    子界面做任何操作都会修改其中的值
      

  8.   

    cdsgajxlp
    能不能详细谈下
    给点代码看看
      

  9.   

    服了 改成下面的样子
    f1: 
    public   string   str   =   null; 
    private   void   button1_Click(object   sender,   EventArgs   e) 
                    { 
                            if   (checkBox1.Checked   ==   true) 
                            { 
                                    frmCustomerinfo   customer   =   new   frmCustomerinfo(); 
                                    customer.ShowDialog(); 
                                    this.str =  customer.str;
                                    MessageBox.show(str);
                            } 
                    } 
    f2: 
    string str;
    private   void   button2_Click(object   sender,   EventArgs   e) 
                    { 
                            str   =   "员工"; 
                            MessageBox.Show(info.str); 
                            this.Close(); 
                    }
      

  10.   

    MDI父窗体f1上面有个button.点击button       ShowDialog   f2子窗体 
    点击f2子窗体上的button,f2关闭的同时把f2的值传到f1上去,怎么办 
    ----------------------------------------------------------------
    父窗体:f1     public string aa = string.Empty;//可以是集合
         //点击button
        f2 newF2 = new f2();
        f2.Owner = this;//this==f1;
        f2.Show();子窗体:f2
        //code....
        ((f1)f2.Owner).aa = "f2_has_changed_itsValue";
        this.Close();//this==f2
      

  11.   

    在f2的窗口中定义一个变量
         ---public f1 aaaaa;
    同时把构造函数改成:
          public f2(f1 asf1)
            {
                InitializeComponent();
                aaaaa=asf1;
            }
        
    在f1 的button按钮中的
        f2 bbbb=new f2(this);
        bbbb。show();这样就ok了。