获取textBox中填入的数字,并将它转化成int型需要用什么类

解决方案 »

  1.   

    int.Parse()抛出异常就有非数字
      

  2.   

    int n = int.Parse(textBox.Text.Trim());
      

  3.   

    对输入要做检察,不过可以偷懒try
    {
       int x = Convert.ToInt32(textBox1.Text.Trim());
    }
    catch
    {
        MessageBox.Show("输入错误!");
    }
      

  4.   

    Convert.ToInt16(textBox.text.trim());
    同意中。。
      

  5.   

    string s = textBox1.Text.Trim();
    if (Regex.Match(@"[^\d]",s) == false)
    {
    int n = int.Parse(s);
    }
      

  6.   

    Convert.ToInt16(textBox.text.trim());一个学者来说,用这个好点嘿 .,我就是用这个,菜鸟(我)
      

  7.   

    try
    {
       int x = Convert.ToInt32(textBox1.Text.Trim());
    }
    catch
    {
        MessageBox.Show("输入错误!");
    }
      

  8.   

    Convert.ToInt32(TextBox1.text.toString());Int.Parse(TextBox1.text.toString());
      

  9.   

    string s = textBox1.Text.Trim();
    if (Regex.Match(@"[^\d]",s) == false)
    {
    int n = int.Parse(s);
    }喜欢这个。是正则表达式吧?想用却觉得麻烦的东西,呵呵
      

  10.   

    如果这个框常用的话
    可以在keypress里检测,不是数字的屏蔽掉
      

  11.   

    double result;
    bool convertSucceed=double.TryParse(textBox1.Text,out result)
    if(!convertSucceed)
    {
    MessageBox.Show("输入的不是数字");
    }
    //成功的话result即为输入的数字
    //再转话成int类型
    int inputvalue;
    if(result <= int.MaxValue && result >= int.MinValue)
    {
    inputvalue= (int)result;
    }
    else
    {
    MessageBox.Show("数值超出范围!");
    }---------------------------------------------------------
    上面的除了带try的 其他的都不是好方法
    我的方法最好 哈哈~~~~~~~~~~~~~~~~~
      

  12.   

    int.Parse()
    OR
    Convert.ToInt32()