public static void Key_Press(KeyPressEventArgs e, TextBox txt)
{
if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
e.Handled = true;
if (e.KeyChar == 46)
{
if (txt.Text.Length == 0)
e.Handled = true;
else
{
float f;
float oldf;
bool b1 = false, b2 = false;
b1 = float.TryParse(txt.Text, out oldf);
b2 = float.TryParse(txt.Text + e.KeyChar.ToString(), out f);
if (b2 == false)
{
if (b1 == true)
e.Handled = true;
else
e.Handled = false;
}
}
}
}
转载请注明原文地址:https://blackberry.8miu.com/read-39293.html