private void numberBox(KeyPressEventArgs e, TextBox t)
{
if (e.KeyChar < '0' || e.KeyChar > '9' || e.KeyChar == 8)
{
if (e.KeyChar == '.')
{
if (!b)
{
e.Handled = true;
}
b = false;
}
else if (e.KeyChar == 8)
{
if (t.Text.Length == 0)
{
return;
}
if (t.Text[this.textBox1.Text.Length - 1].Equals('.'))
{
b = true;
}
}
else
{
e.Handled = true;
}
}
}
C# 文本框只能输入数字
最新推荐文章于 2025-06-27 12:17:10 发布