c#textbox 只能输入数字,小数点.怎么做
展开全部
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)13 && e.KeyChar != (char)8)
{
if(e.KeyChar == ‘.’)
{
e.Handled = false;
}
else
e.Handled = true;
MessageBox.Show("只能输入数字和小数点!");
}
else
{
e.Handled = false;
}
}
{
if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)13 && e.KeyChar != (char)8)
{
if(e.KeyChar == ‘.’)
{
e.Handled = false;
}
else
e.Handled = true;
MessageBox.Show("只能输入数字和小数点!");
}
else
{
e.Handled = false;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询