Arrow keys and changing control's focus hang the application
Posted
by sthay
on Stack Overflow
See other posts from Stack Overflow
or by sthay
Published on 2009-05-28T11:50:01Z
Indexed on
2010/04/08
15:33 UTC
Read the original article
Hit count: 287
I have a usercontrol that contains a FlowLayoutPanel
(topdown flow) with a bunch of radiobuttons. The control exposes a CheckedChanged
event that fires whenever one of the radiobuttons's check changed.
My form contains the usercontrol and a textbox. I subscribe the usercontrol's CheckedChanged
event and depending on which radiobutton gets checked, I either disable the textbox or put a focus inside the textbox.
All this works fine with mouseclick when changing the radiobutton's check state. However, this will hang indefinitely when using the arrow keys. I don't understand why the difference.
The following are steps to reproduce the behavior I'm seeing:
Create a usercontrol and drop a
FlowLayoutPanel
control and set itsFlowDirection = TopDown
. Then add two radiobuttons to theFlowLayoutPanel
.Provide an event handler in the usercontrol
public event EventHandler CheckedChanged { add { radioButton2.CheckedChanged += value; } remove { radioButton2.CheckedChanged -= value; } }
Create a windows form and drop the above user control. Add a textbox and set
Enabled
to False. Subscribe to the usercontrol'sCheckedChanged
event as followsprivate void userControl11_CheckedChanged(object sender, EventArgs e) { textBox1.Select(); }
Run. Notice that if you use the mouse to click between the radiobuttons, thing works fine; but it will crash if you use the up/down arrow keys.
© Stack Overflow or respective owner