在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
一.KeyPress事件 private void txt_loopNum_KeyPress(object sender, KeyPressEventArgs e) { CheckNum(sender, e); } 二.CheckNum方法 public void CheckNum(object sender, KeyPressEventArgs e) { //阻止从键盘输入键 e.Handled = true; if (e.KeyChar >= '0' && e.KeyChar <= '9' || (e.KeyChar == (char)8)) { if (e.KeyChar == (char)8) { e.Handled = false; return; } else { int len_lookNum = ((TextEdit)sender).Text.Trim().Length; if (len_lookNum < 8) { if (len_lookNum == 0 && e.KeyChar != '0') { e.Handled = false; return; } else if (len_lookNum== 0) { e.Handled = true; return; } e.Handled = false; return; } else { MessageBox.Show("输入数字过大"); } } } }
|
请发表评论