Winform中限制输入两位小数
public static bool txtboxliangweixiaoshu(KeyPressEventArgs e,string tbtext)
{
if (tbtext.Trim().Length > 0 && tbtext.Trim().IndexOf(".") > 0)
{
if (tbtext.Trim().IndexOf(".") < tbtext.Trim().Length - 1)
{
if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))
{
return true;
}
else
{
if ((tbtext.Trim().Length - tbtext.Trim().IndexOf(".")) > 2)
{
if (e.KeyChar == 8)
{
return false;
}
else
{
return true;
}
}
else
{
return false;
}
}
}
else
{
if (e.KeyChar == 8 || e.KeyChar != 46)
{
return false;
}
else
{
return true;
}
}
}
else
{
if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar) && e.KeyChar != 46)
{
return true;
}
else
{
if (e.KeyChar == 46 && tbtext.Trim().Length == 0)
{
return true;
}
else
{
return false;
}
}
}
}
private void tb_shishoubaofei_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = UIContrl.txtboxliangweixiaoshu(e, this.tb_shishoubaofei.Text);
}
浙公网安备 33010602011771号