I'm working on a wpf app and i want to get the value of textbox i want to use KeyDown & KeyPress to check if the text is a numeric value but when i write KeyPress the compilator underlined the proprity so i can't use it .
private void sb_KeyDown_1(object sender, System.Windows.Input.KeyEventArgs e)
{
nonNumberEntered = false;
// Determine whether the keystroke is a number from the top of the keyboard.
if (e.KeyCode < Keys.D0 || e.KeyCode > Keys.D9)
{
// Determine whether the keystroke is a number from the keypad.
if (e.KeyCode < Keys.NumPad0 || e.KeyCode > Keys.NumPad9)
{
// Determine whether the keystroke is a backspace.
if (e.KeyCode != Keys.Back)
{
// A non-numerical keystroke was pressed.
// Set the flag to true and evaluate in KeyPress event.
nonNumberEntered = true;
}
}
}
//If shift key was pressed, it's not a number.
if (Control.ModifierKeys == Keys.Shift)
{
nonNumberEntered = true;
}
}
and it underlined also e.KeyCode and e.KeyNumPad0 .... what should i do ?