只能输入数字和字符

/// <summary>
/// 只能输入数字和字符
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtTerminalNum_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;
}
}

posted @ 2019-11-14 17:25  CocoWang  阅读(260)  评论(0编辑  收藏  举报