在应用系统的开发中,我们经常需要限制用户的输入,以高效无误的开展工作,比如说,电话号码,仅能位数字等。对于某一个textbox控件的keypress事件编程,可以找到keypress双击,具体代码如下:

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)

{

  if((e.KeyChar != 8 && !char.IsDigit(e.KeyChar))&&e.KeyChar != 13)

    {

          messageBox.show("只允许输入数字");

           e.handled = true;   

     }

}

 

相关文章:

  • 2021-10-18
  • 2023-01-24
  • 2021-08-21
  • 2021-12-15
  • 2021-06-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案