请问如何遍历窗体中的一个groupbox中的控件?
用foreach(control c in this.Controls)只能遍历form里的控件,不能遍历form中gb中的控件,请问要怎么才能遍历gb中的控件,谢谢

解决方案 »

  1.   

    跟FORM差不多,遍历时指定为groupbox中的控件就行了!
    foreach (Control ctl in this.groupBox1.Controls)
    {
       MessageBox.Show(ctl.Name.ToString());
    }
      

  2.   

    foreach(ctrl c in this.groupbox1.Controls)
    {
     ....
    }Form:
    foreach(ctrl c in this.Controls)
    {
      if (ctrl is GroupBox) 
      {
        foreach(gc c in ctrl.Controls)
        {
          ....
        }
      } ....
    }
      

  3.   

    foreach(control c in this.Controls)
    {
    if(c is Groupbox)//加上这个条件就可以了
    {
    MessageBox.show(c.Name)
    }
    }