用正则表达式
System.Text.RegularExpressions.Regex mRegex = new System.Text.RegularExpressions.Regex(@"^\d+(\.\d{1,2})?$");
System.Text.RegularExpressions.Match mMatch = mRegex.Match(paramEvent.FormattedValue.ToString()); if (!mMatch.Success)
{
MessageBox.Show("Failed!");
}
else
{
MessageBox.Show("OK");
}
System.Text.RegularExpressions.Regex mRegex = new System.Text.RegularExpressions.Regex(@"^\d+(\.\d{1,2})?$");
System.Text.RegularExpressions.Match mMatch = mRegex.Match(paramEvent.FormattedValue.ToString()); if (!mMatch.Success)
{
MessageBox.Show("Failed!");
}
else
{
MessageBox.Show("OK");
}
{
if ( e.KeyChar > (char)47 && e.KeyChar < (char)58 || e.KeyChar ==(char)8 ||e.KeyChar==(char)46)
{
e.Handled = false;
}
else
{
e.Handled = true;
}
}