private bool invalidNumeric(char key)
{
bool handled = false;
NumberFormatInfo numberFormatInfo = CultureInfo.CurrentCulture.NumberFormat;
string decimalSeparator = numberFormatInfo.NumberDecimalSeparator;
string negativeSign = numberFormatInfo.NegativeSign;
string keyString = key.ToString();
if (Char.IsDigit(key))
{
// Digits are OK
}
else if (AllowDecimalSeperator && keyString.Equals(decimalSeparator))
{
if (Text.IndexOf(decimalSeparator) >= 0)
{
handled = true;
}
}
else if (AllowNegativeSign && keyString.Equals(negativeSign))
{
if (Text.IndexOf(negativeSign) >= 0)
{
handled = true;
}
}
else if (key == '\b')
{
// Backspace key is OK
}
else if ((ModifierKeys & (Keys.Control)) != 0)
{
// Let the edit control handle control and alt key combinations
}
else
{
// Swallow this invalid key and beep
handled = true;
}
return handled;
}