怎样使用GetEnumerator得到窗体frmPO中的所有控件(也要包括容器控件中的控件)
           frmPO.Controls.GetEnumerator()不知道怎样去写

解决方案 »

  1.   

      IList<Control> TT = new List<Control>();            GetControls(this, TT);
                for (int i = 0; i != TT.Count; i++)
                {
                    MessageBox.Show(TT[i].Name);
                }  public static void GetControls(Control p_Control, IList<Control> p_SubControlList)
            {
                foreach (Control _SubControl in p_Control.Controls)
                {
                    p_SubControlList.Add(_SubControl);
                    GetControls(_SubControl, p_SubControlList);
                }
            }
    不知道是不是你的意思
      

  2.   

    谢谢楼上的,不错若用GetEnumerator又怎样写呢
      

  3.   


    IEnumerator ie = frmPO.Controls.GetEnumerator();
    while(ie.MoveNext())
    {
        MessageBox.Show(ie.Current.GetType().FullName);
    }
      

  4.   

    IEnumerator ie = frmPO.Controls.GetEnumerator();
    while(ie.MoveNext())
    {
        MessageBox.Show(ie.Current.GetType().FullName);
    }