/// <summary>
/// 检查只能输入小数点,数字和退格
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Numeric_Check(object sender, KeyPressEventArgs e)
{
TextBox tb = (TextBox)sender;
if (char.IsNumber(e.KeyChar) || e.KeyChar == (char)Keys.Back | e.KeyChar == '.')
{
e.Handled = false;
int j = 0;
for (int i = 0; i < tb.Text.Length; i++)
{
if (tb.Text[i] == '.')
{
j++;
}
if (j >= 1)
{
if (e.KeyChar == '.')
{
e.Handled = true;
}
break;
}
}
}
else
{
e.Handled = true;
}
}
/// 检查只能输入小数点,数字和退格
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Numeric_Check(object sender, KeyPressEventArgs e)
{
TextBox tb = (TextBox)sender;
if (char.IsNumber(e.KeyChar) || e.KeyChar == (char)Keys.Back | e.KeyChar == '.')
{
e.Handled = false;
int j = 0;
for (int i = 0; i < tb.Text.Length; i++)
{
if (tb.Text[i] == '.')
{
j++;
}
if (j >= 1)
{
if (e.KeyChar == '.')
{
e.Handled = true;
}
break;
}
}
}
else
{
e.Handled = true;
}
}