private void txtNewPort_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = e.KeyChar < '0' || e.KeyChar > '9';
if (e.KeyChar == (char)8)//8指的是back键
{
e.Handled = false;//false表示可以操作
}
if (e.Handled)
{
MessageBox.Show("请输入数字");
}
}
c#中解决只能让用户输入数字的方法
最新推荐文章于 2025-03-29 13:32:02 发布