c# – Working with radioButton in C # WinForms


I am writing a program where you need to use the left and right keys. You need to choose the correct answer and switch with the "left" or "right" key to go to another question. Everything works, only there is one problem, when you press a key from the keyboard, it first switches the value of the radioButton , and only then moves on to another question.

Is it possible to set some property for the radioButton so that it does not respond to the keyboard?


try for all radiobuttons to set the caydown event for this method (you do not need to duplicate it – everyone has the same method)

private void radioButton1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
   if (e.KeyCode == System.Windows.Forms.Keys.Left || e.KeyCode == System.Windows.Forms.Keys.Right
    || e.KeyCode == System.Windows.Forms.Keys.Up || e.KeyCode == System.Windows.Forms.Keys.Down)
    e.SuppressKeyPress = true;

As long as the focus is on an element subscribed to such a handler, the keys are simply ignored. At all. No other handlers are called.

Scroll to Top