protected override void OnTextBoxKeyPress(object source, KeyPressEventArgs e) {
if ((ModifierKeys & ~Keys.Shift) != Keys.None) {
return;
}
NumberFormatInfo nfi = CultureInfo.CurrentCulture.NumberFormat;
string pressedKey = e.KeyChar.ToString ();
if ((pressedKey != nfi.NegativeSign) && (pressedKey != nfi.NumberDecimalSeparator) &&
(pressedKey != nfi.NumberGroupSeparator)) {
string acceptable = hexadecimal ? "\b0123456789abcdefABCDEF" : "\b0123456789";
if (acceptable.IndexOf (e.KeyChar) == -1) {
// FIXME: produce beep to signal that "invalid" key was pressed
// prevent the key from reaching the text box
e.Handled = true;
}
}
base.OnTextBoxKeyPress(source, e);
}