2个主窗体怎样判断是哪个主窗体调用子窗体

解决方案 »

  1.   

    this.ParentForm 这个获取不到
      

  2.   


    //主窗体
                Form2 f2 = new Form2();
                f2.Owner = this;  //实例化子窗体时加一句
                f2.Show();
    //子窗体
               MessageBox.Show(this.Owner.Name); //获取父窗体 
      

  3.   


                foreach (Control c in this.Owner.Controls)  //遍历父窗体中的空间
                {
                    if (c is TextBox)
                    {
                        c.Text="2121212";
                    }
                }
      

  4.   

    把你需要获取的控件设置为PUBLIC
    子窗体里面强制转换
    ((Form2)this.Owner).控件 
      

  5.   

    这么多人和你说了 this.Owner 你都没看见么???
      

  6.   

     我把控件放到panle里获取不到
      

  7.   

                foreach (Control c in this.Owner.Controls)
                {
                    if (c is Panel)
                    {
                        foreach (Control cc in c.Controls)
                        {
                            if (cc is TextBox)
                            {
                              cc.Text = "2121212";
                            }
                        }
                    }
                }方法很多