if (!Char.IsNumber(e.KeyChar) && !Char.IsPunctuation(e.KeyChar) && !Char.IsControl(e.KeyChar))
{
e.Handled = true;//消除不合适字符
}
else if (Char.IsPunctuation(e.KeyChar))
{
if (e.KeyChar != '.' || this.txt4.Text.Length == 0)//小数点
{
e.Handled = true;
}
if (txt4.Text.LastIndexOf('.') != -1)
{
e.Handled = true;
}
}