>>>转换
use System.Convert.ToInt32 or System.Int32.Parse method>>>限制在textbox只能输入数值
use some masked textbox, for example, see
http://www.codeproject.com/cs/miscctrl/maskedcsedit.asporhttp://www.csharphelp.com/archives/archive163.html

解决方案 »

  1.   

    Try{
        int astring = Convert.ToInt32(Textbox.text);
       }
    Catch{
       ErrorMessage("请输入数字串");
       }
    //不知道这样行不行
      

  2.   

    输入数值的话:只能输入0-9,回车键,退格键,
    在keyPress中输入如下的代码:其实的以此类推
    if ( !(((e.KeyChar >= (char)48) && (e.KeyChar <= (char)57)) || (e.KeyChar == (char)13) || (e.KeyChar == (char)46) || (e.KeyChar == (char)45) || (e.KeyChar == (char)8)))
    {
    e.Handled = true;
    }
      

  3.   

    你在 文本框的 textchange 事件中检查Try{
        int astring = Convert.ToInt32(Textbox.text);
       }
    Catch{
         TextBox1.Text="";
          }
      

  4.   

    xhjdxx(dd) :你的好像有点问题,如果用户直接用复制粘贴 就没法控制了。
      

  5.   

    .NET Framework 正则表达式下面的代码示例使用静态 Regex.Replace 方法从字符串中抽出无效字符。您可以使用这里定义的 CleanInput 方法,清除掉在接受用户输入的窗体的文本字段中输入的可能有害的字符。CleanInput 在清除掉除 @、-(连字符)和 .(句点)以外的所有非字母数字字符后返回一个字符串。[Visual Basic]
        Function CleanInput(strIn As String) As String
            ' Replace invalid characters with empty strings.
            Return Regex.Replace(strIn, "[^\w\.@-]", "")
        End Function[C#]
        String CleanInput(string strIn)
        {
            // Replace invalid characters with empty strings.
            return Regex.Replace(strIn, @"[^\w\.@-]", ""); 
        }
      

  6.   

    自己写一个类似VB的IsNumeric方法调用就行了