WinForm 校验只能输入数字英文字母退格键
作者:互联网
1.校验只能输入数字、小数点、退格键的代码
private void TextBoxKeyPress(object sender, KeyPressEventArgs e) { //================48代表0,57代表9,8代表退格删除,46代表小数点 if ((e.KeyChar <= 48 || e.KeyChar >= 57) && (e.KeyChar != 8) && (e.KeyChar != 46)) e.Handled = true; }View Code 2.在需要调用的地方调用
private void Frm_Load(object sender, EventArgs e) { //校验只能输入数字 this.txtCount.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TextBoxKeyPress); }View Code
标签:46,KeyChar,校验,private,View,退格,WinForm 来源: https://www.cnblogs.com/bmyblogs/p/10875582.html