foreach(object obj in this.Controls)
 {
     if (obj.GetType() == typeof(TextBox))
       {
          //....
       }
}

解决方案 »

  1.   

    private Control FindControl(Control container, string controlName)
            {
                if (container.Name == controlName)
                {
                    return container;
                }
                Control findControl = null;
                foreach (Control control in container.Controls)
                {
                    Console.WriteLine(control.Name);
                    if (control.Controls.Count == 0)
                    {
                        if (control.Name == controlName)
                        {
                            findControl = control;
                            break;
                        }
                    }
                    else
                    {
                        findControl = FindControl(control, controlName);
                        if (findControl != null)
                        {
                            break;
                        }
                    }
                }
                return findControl;
            }这个是根据控件名称查找控件的例子
    你稍微改改就可以了
      

  2.   

    foreach(object obj in this.Controls)
     {
         if (obj.GetType() == typeof(TextBox))
           {
              //....
           }
    }
    这个应该行。
      

  3.   

    foreach(object obj in this.Controls)
     {
         if (obj.GetType() == typeof(TextBox))
           {
             hashtable.add(obj.name,obj .text);
           }
    }
      

  4.   

    应该是一个递归调用。
    如果Form上放了N多的Panel或者Container,就要考虑了楼上所有的回答都没考虑这些东西。
      

  5.   

    递归, 递归的时候看看 该控件还有没有子控件 。   
    private void a(控件 )
    {
    if (有子控件)
    {
    a(子控件)
    }
    if (控件类型为文本框)
    {
    找到文本框 
    }
    }
      

  6.   

    foreach form controls~~,ls都说光了~~
      

  7.   

    csrwgs(你血所加?) ( ) 
    应该是一个递归调用。
    如果Form上放了N多的Panel或者Container,就要考虑了楼上所有的回答都没考虑这些东西。======================================lovefootball(蟑螂(生活就是扯淡--做人要放低姿态)) ( ) 说的 难道没有考虑其他容器的问题? 呵呵,麻烦看清楚了再说
      

  8.   

    轉自網上一位高手,先謝謝他!
    他做的是回車光標移到下一個文本框。裡面的方法原理應該是一樣的       /// <summary> 
            /// 光標移到下一個文本框
            /// </summary>
            /// <param name="keyData"></param>
            /// <returns></returns>
            protected override bool ProcessDialogKey(Keys keyData)
            {
                if (keyData == Keys.Enter && this.ActiveControl is TextBox)
                {
                    Control ctr = this.GetNextControl(this.ActiveControl, true);
                    while (!(ctr is TextBox))
                    {
                        ctr = this.GetNextControl(ctr, true);
                    }
                    if (ctr is TextBox)
                    {
                        ctr.Select();
                    }
                }            return base.ProcessDialogKey(keyData);
            }
      

  9.   

    1楼的已经是很正点的办法了.想保存起来,可以考虑用TextBox的数组,比用hashTable效率高
      

  10.   

    csrwgs 说的对,要用递归。
      

  11.   

    两个多月了还不结??csrwgs:
    应该是一个递归调用。
    如果Form上放了N多的Panel或者Container,就要考虑了楼上所有的回答都没考虑这些东西。
    ----------------》
    不好意思
    我好像就是递归~~~
    麻烦先看看别人的代码在说话~~~~