private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar!=8&&!Char.IsDigit(e.KeyChar)&&e.KeyChar!=’.’)
{
e.Handled = true;
}
}
///或者
private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar!=’/b’&&!Char.IsDigit(e.KeyChar)&&e.KeyChar!=’.’)
{
e.Handled = true;
}
} ......
C#(winform)文本框只能输入数字和退格键和小数点
最新推荐文章于 2024-01-31 10:47:53 发布
本文介绍了一个简单的TextBox事件处理程序,该程序能够确保用户仅能输入数字和小数点,有效防止了非法字符的输入,适用于需要精确数值输入的应用场景。
2275





