怎样获得一个窗体上的所有组件(这里说的组件是指象SaveFileDialog那样的不是在设计窗体上,而是位于设计窗体下方的组件)?
另外Control control in FormName.Controls是只获得窗体上的控件(不包括上面说的组件)吗?谢谢

解决方案 »

  1.   

    private GetControls(Control ctrl)
    {
       foreach(Control c in ctrl.Controls)
       {
          // 处理c
          if(c.HasChildren)
          {
             GetControls(c);  // 递归
          }
        }
    }
      

  2.   

                foreach (Component comp in this.components.Components)
                    MessageBox.Show(comp.GetType().Name);
      

  3.   

    假如我要检查所有MDIChichren窗,在下面的代码中this要换成foreach中的f,
    请问怎么改写?谢谢foreach (Form f in this.MdiChildren)
        {
           foreach (Component comp in this.components.Components) 
         //因为this代表当前窗体对象,若改为f,f后没components,请问怎么改
           MessageBox.Show(comp.GetType().Name);
        }
      

  4.   

    谢谢楼上的
    我若将this.components.Components中的this换为foreach (Form f in this.MdiChildren)中的f,系统提示出错的
      

  5.   

    不一定所有窗口都有组件的foreach (Form f in this.MdiChildren)
        if(f.componets != null)
            foreach (Component comp in this.components.Components)
                 MessageBox.Show(comp.GetType().Name);
      

  6.   

    忘了把this改成f了:foreach (Form f in this.MdiChildren)
        if(f.componets != null)
            foreach (Component comp in f.components.Components)
                 MessageBox.Show(comp.GetType().Name);
      

  7.   

    楼上的写f.后系统只能智能感知出f.Container,而没有f.components啊,请问怎么做