C# Winform textBox 只允许输入数字

private void textBox1_KeyPress(object sender,KeyPressEventArgs e)  
{  
      //数字0~9所对应的keychar为48~57
      e.Handled = true;  
      //输入0-9
      if ((e.KeyChar >= 47 && e.KeyChar <= 58) || e.KeyChar == 8)  
      {  
            e.Handled = false;  
       }  
} 

限制textBox的输入,只能输入数字

posted @ 2014-06-09 11:28  仆人  阅读(1586)  评论(0编辑  收藏  举报