遍历所有的控件,如果他的类型返回值是textbox, 在验证里面的值是否是数字类型!

解决方案 »

  1.   

    //假定文本框都直接再窗体上
    foreach(System.Windows.Forms.TextBox tempControl in this.Controls  )
    {
       if(isNum(tempControl.Text))
       {
       }
       else
       {}
    }
      

  2.   

    string strNum = string.Empty;//穷举所有的控件
    foreach( Control ctrl in this.Controls)
        if( ctrl is TextBox)
        { 
            //获得该TextBox的Text
             strNum = ((TextBox)ctrl).Text;
              .............
        }
      

  3.   

    如果涉及嵌套,例如textbox在panel上,还需要使用递归算法
      

  4.   

    get a masked textbox:http://www.thecodeproject.com/cs/miscctrl/maskedcsedit.asphttp://www.c-sharpcorner.com/Code/2004/Jan/MaskedTextBoxControl.asp