遍历所有控件和子控件

       List<Control> allControl = new List<Control>();

       private void GetControl(Control.ControlCollection ctc)
       {
           foreach (Control ct in ctc)
           {
               allControl.Add(ct);
               //当控件有子控件时,需要用递归的方法遍历
               if (ct.HasChildren)
               {
                   GetControl(ct.Controls);
               }
           }
       }

 

      调用 GetControl(form.controls) 遍历窗体所有控件。

posted @ 2009-06-02 13:50  cindymeng  阅读(368)  评论(0编辑  收藏  举报