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
原文地址:https://www.cnblogs.com/bmyblogs/p/10875582.html