Hello everybody,
I like theEnter-key to behave like Tab and Shift+Enter like Shift+Tab to step through a form. Works fine for simple forms but breaks down if you use nested user controls.
To reproduce:Build a UserControl (MyUserControl) thatsimply contains2 textboxes. Add 2 instances of MyUserControl to a form. Add a timer to the form, which calls SelectNextControl every 2sec to move the focus to the previouscontrol every 2 sec.
| 1 |
privatevoidtimer1_Tick(objectsender,EventArgse){ |
| 2 |
SelectNextControl(GetActiveControl(ActiveControl),false,true,true,true); |
| 3 |
} |
| 4 |
|
| 5 |
publicstaticControlGetActiveControl(ControlpControl){ |
| 6 |
if(pControl.Focused){ |
| 7 |
returnpControl; |
| 8 |
} |
| 9 |
for(inti=0;i<pControl.Controls.Count;i++){ |
| 10 |
if(pControl.Controls[i].ContainsFocus){ |
| 11 |
returnGetActiveControl(pControl.Controls[i]); |
| 12 |
} |
| 13 |
} |
| 14 |
returnnull; |
| 15 |
} |
| 16 |
|
GetActiveControl() is a little helper to determine the focussed-control with which the SelectNextControl()-Method is started. If you don't use the helper, you step from user control to user control and skip the second textbox in each user control.
Unfortunately, the focus is circling withinthe textboxes of only one user control. It never reaches the other user control.Does anybody know, if this is a bug? Manually hitting Shift-Tab circles through the textboxes as you expect.
Using SelectNextControl with the "forward"-flag works perfectly fine even with nested user controls. BTW: The "wrap"-flag isn't respected when going backwards.
thanks, Helge