.net c# winform TextBox 只能输入数字和字母、退格键
只需要处理 KeyPress 事件即可,代码如下
private void ztxttwo_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar >= 'a' && e.KeyChar <= 'z') || (e.KeyChar >= 'A' && e.KeyChar <= 'Z') || (e.KeyChar >= '0' && e.KeyChar <= '9') || (e.KeyChar == 8))
{
e.Handled = false;
}
else
{
e.Handled = true;
}
}