c#怎样让textbox中只能输入数字

2025-04-07 23:28:25
推荐回答(2个)
回答1:

private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar <= 48 || e.KeyChar >=57) && (e.KeyChar != 8) && (e.KeyChar != 46))
{
e.Handled = true;
}
}

回答2:

在文本框keypress方法里面判断