private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
int b=e.KeyChar ;
if (this.textBox1.Text.Length ==0)//只能输入数字而不是字符
{
if (char.IsDigit(e.KeyChar))
{
e.Handled = false;
}
else
{
e.Handled = true;
}
}
else
{
if ((b<48 && b!=8 && b != '.') || b>57 )
e.Handled =true ;
else
{
string a=textBox1.Text;
int j=0;
for(int i=0;i<textBox1.Text.Length;i++)
{
if (a[i]=='.') j++;
}
if (j>0 && e.KeyChar=='.')
e.Handled = true;
else
e.Handled =false ;
}
}
}
}