http://dotnet.blogger.cn/commansource/articles/383.aspx

解决方案 »

  1.   

    public static bool Chk(string ch)
    {
    string Digit= "1234567890";
    for(int i =0;i<ch.Length ;i++)
    {
    if (Digit.IndexOf( ch[i],0) ==-1) 
    {
    return false;
    }
    }
    return true;                                    
    }
      

  2.   

    private void txtTest_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) 

    if(!char.IsNumber(e.KeyChar)) e.Handled = true; 
      

  3.   

    最有效的是正则表达式To : Aallonlin(风之力) 假如用户是用复制,粘贴进来的话就不能用了
      

  4.   

    我以前没注意过这个问题。
    谢谢 showtimenow(景) 的提醒!