用try ,catchtry
{
  int i=Int32.Parse(text1.text)
  
}
catch
{
  MessageBox.Show("不是数字")
}

解决方案 »

  1.   

    try
    {
      int.Parse(text1.text);
    }
    catch
    {
      MessageBos.Show("no");
    }
      

  2.   

    不会吧,还要这么写??
    VB里面只要一下isnumeric就可以了,我想C#里面可能也有这样一个东东吧?
      

  3.   

    protected bool isDecimal(mytest)
    {
    try
    {
      int aa = Convert.ToDecimal(mytest);
      return true;
    }
    catch
    {
      return false;
    }
    }if(isDecimal(text1.Text))
    {
    }
      

  4.   

    用try catch方法的话我就不用发贴子了,我以为有简便方法的。
      

  5.   

    回答try-catch的全部拖出去tjjtds,嗯
      

  6.   

    Sunmast(速马, Reloading...) 有什么高招请赐教啊!!
      

  7.   

    http://community.csdn.net/Expert/topic/3310/3310475.xml
      

  8.   

    try catch 是异常处理,我觉得不适合用在这个地方..
      

  9.   

    判断字符还是数字的方法。 
    using System;
    using System.Text.RegularExpressions; 
    using System.Collections;public class MyClass
    {
     public static void Main()
     {
      string aa = "11";
      
      if(Regex.Replace(aa,@"\d*","",RegexOptions.None).Length == 0)
      {
       Console.WriteLine("Numeric");
      }
    }
      

  10.   

    写了个简单的测试,看看性能差异(单位毫秒): try-catch regular-expression
    "12345a" 4.93 7.6/1000
    "12345" 0.5/1000 7.9/1000
      

  11.   

    if (isnumeric(text1.text)) then
    {
     msgbox("Text")}
      

  12.   

    这个问题好像真的有几十遍了!!
    用javascript判断:var obj=document.getElementById("Text1");//strRegular="/^(\-)?(0|[1-9](\d)*)(\.(\d)+)?$/";  //float类型
    strRegular="/^(\-)?(0|[1-9](\d)*)$/";  //整型
    if(strRegular.test(obj.value))
    {
       alert('是数字');
    }
    else
    {
        alert('不是数字')
    }C#里的判断方法上面有了!
      

  13.   

    if(int.phrase(txtbox.text.tostring())){
    retrun;
    }
      

  14.   

    isnumeric 的原形似乎也是try catch的..
      

  15.   

    public static bool isNumber(string isNum)
    {
    bool bisNum = true;
    char[] chars = isNum.ToCharArray(0, isNum.Length);
    for(int i=0; i<isNum.Length; i++)
    {
    if(!char.IsNumber(chars[i]))
    {
    bisNum = false;
    break;
    }
    }
    return bisNum;
    }
      

  16.   

    还是试试我的吧:
    this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtAge_KeyPress);private void textBox1_KeyPress(object sender,System.Windows.Forms.KeyPressEventArgs e)
    {
    if((e.KeyChar<48||e.KeyChar>57)&&e.KeyChar!=8)
    {这是你的代码了}
    }