I have the problem, that i like to programm a ui in windows forms. there i only want to allow user input through the buttons from the ui, which i already have ready, and number input through the keys on the keyboard. All other keys should not work. How can I do this?
Asked
Active
Viewed 93 times
1 Answers
1
Handle the KeyDown event:
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
e.Handled = true;
// Top row of numbers or keypad
if ((e.KeyCode < Keys.D0 || e.KeyCode > Keys.D9) || (e.KeyCode < Keys.NumPad0 || e.KeyCode > Keys.NumPad9))
{
// Do something with the number
}
}

Matthew M.
- 932
- 10
- 17