只需要在文本框的keyPress事件中写如下代码即可:

 

1    private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
2   {
3       //只能是0~9之间的数字 并支持删除键
4        if (!((e.KeyChar >= '0' && e.KeyChar <= '9'|| e.KeyChar == ''))
5       {
6           e.Handled = true;
7       }
8             
9   }

相关文章:

  • 2021-07-28
  • 2021-10-22
  • 2022-12-23
  • 2022-12-23
  • 2021-08-10
  • 2021-07-26
  • 2021-06-02
  • 2021-09-01
猜你喜欢
  • 2022-01-09
  • 2021-06-15
  • 2022-12-23
  • 2021-07-08
  • 2022-12-23
相关资源
相似解决方案