using System.Text.RegularExpressions;
if (Regex.IsMatch(userstring,"[\\d.]"))
  无效
else
 有效

解决方案 »

  1.   

    try
    {
        int temp = Int32.Parse(txtbox1.Text)
    }
    catch
    {
       错误
    }
      

  2.   

    用duanxl() 我已经解决了问题,但是wxd719()的方法也挺好的,就是如何改进,连小数都不可以输呢?
      

  3.   

    public bool checknumber(string NUM)
    {
    string a="0123456789.";
    if(NUM.Length==0)
    {
    return false;
    }
    for(int i=0;i<NUM.Length;i++)
    {
    int c=a.IndexOf(NUM.Substring(i,1));
    if(c==-1)
    {
    return false;
    }
    }
    return true;
    }
    if(checknumber()==true)
    {
    //是整数
    }
    else
    {
    //不是整数
    }
      

  4.   

    public bool checknumber(string NUM)
    {
    string a="0123456789.";
    if(NUM.Length==0)
    {
    return false;
    }
    for(int i=0;i<NUM.Length;i++)
    {
    int c=a.IndexOf(NUM.Substring(i,1));
    if(c==-1)
    {
    return false;
    }
    }
    return true;
    }
    if(checknumber(TextBox1.Text.Trim())==true)
    {
    //是整数
    }
    else
    {
    //不是整数
    }
      

  5.   


    public bool checknumber(string NUM)
    {
    string a="0123456789.";//如果只是整数的话不要那一个.//要点就可以输入小数
    if(NUM.Length==0)
    {
    return false;
    }
    for(int i=0;i<NUM.Length;i++)
    {
    int c=a.IndexOf(NUM.Substring(i,1));
    if(c==-1)
    {
    return false;
    }
    }
    return true;
    }
    if(checknumber(TextBox1.Text.Trim())==true)
    {
    //是整数
    }
    else
    {
    //不是整数
    }