private void txtPrice_KeyPress(object sender, KeyPressEventArgs e)
{
if (!((e.KeyChar >= '0' && e.KeyChar <= '9') || e.KeyChar == '.' || e.KeyChar == ''))
{
e.Handled = true;
}
else
{
if (e.KeyChar == '.')
{
string str = txtPrice.Text;
int num = str.IndexOf('.');
if (num != -1)
{
e.Handled = true;
}
}
}
}
转载于:https://www.cnblogs.com/Prince/archive/2009/05/31/1492795.html