1

I seem to have an issue with keyboard control and TabStops in my VB.NET application.

I already searched here and on the web and found a few related topics (not 1000% the same issue) and some of the solutions I could find on the web did not help in my case.

I am not sure if my problem is mainly related to the use of group boxes and could be solved. As a rough depiction of the controls setup see here a schematic overview:

GroupBox1____ GroupBox2_____ GroupBox3

Control1_______ Control4________ Control7

Control2_______ Control5________ Control8

Control3_______ Control6________ Control9

I have set the TabIndex for the group boxes and controls in order so that Tab can cycle through Control1 to control9. When the Form loads I give the focus to one of the controls by code to have an initial focus on one control. That works without any problem. Also cycling backward with Shift-Tab works just fine.

Now the problem is when a user accidentally goes past the last control, e.g. Control9 has focus and he presses TAB or Control1 has focus and he presses Shift-TAB the control loses focus but it does not jump to the next lowest or highest TabIndex control with TabStop=True.

Basically, it enters a state where no control has a focus, and pressing TAB or Shift-TAB does nothing. (I would expect it to go around in a round-robin fashion)

The only way is then to click on any control with the mouse to regain focus and regain keyboard control. Not sure if this is a bug or a feature.

I understand that VB.NET handles each groupbox as an individual set of controls, but not sure if this might be related to my problem.

Also there are some other controls on the form which have higher TabIndex numbers, but TabStop set to False (most of them are no input controls anyway, e.g. some pictureboxes or labels). That should normally not interfere in my understanding.

Is it relevant what type of control they are? (e.g. Control9 is a checkbox and COntrol1 is a radio button control)

I already tried as a workaround e.g. to catch a keypress event or lost focus event to force a re-focus on the next control in sequence by code, but for some reason, I am not able to do it programmatically as some of the tried events do not seem to fire when using TAB or Shift-Tab.

Is someone familiar with this problem and has a suggestion on how I could move e.g. from Control9 to Control1 when hitting TAB? (or from Control1 to Control9 when hitting Shift-TAB)?

Oscar Diez
  • 83
  • 1
  • 11
  • As for _But in my case, once the last control in the group loses its focus by hitting Tab it will not regain focus on any other control anymore at all. (no matter how often I hit TAB afterward)_. That doesn't happen as you can see in the gifs. Double check your layout and code. – dr.null Nov 11 '21 at 16:51
  • It seems it is related that my groupboxes are not on the main form but the form has a SplitContainer with two panels (upper and lower). The group boxes with all controls are in the upper Panel1 used as a menu. When I lose focus what happens is Panel 2 gets focus (it hosts a Browser plugin). I already tried to set the SplitContainer to a unique high TabIndex (99) and the TabStop property set to False, but it still gets Tabstops...how can I force that tabstops remain only in Panel 1 of the Splitcontainer. Both panels themselves do not seem to have any TabStop property in the designer. – Oscar Diez Nov 11 '21 at 17:25
  • **(it hosts a Browser plugin).** Which is stealing and keeping the focus. See [this](https://stackoverflow.com/questions/1562619/prevent-webbrowser-control-from-stealing-focus) and the similar posts. – dr.null Nov 11 '21 at 17:39

1 Answers1

0

The probblem was caused by a SplitContainer control which had the groupboxes with the controls in the first panel and a CEFSharp browser plugin added to a second panel during the Form Load event.

It was initially not so obvious to me because the browser is not shown in the VS designer and only loads at runtime.

The browser plugin was hijacking the TabStops after it was gettig the focus.

The solution was to change the TabStop property of the CEFSharp browser plugin to False by code inside the Form Load event after the browser plugin was initiated and added to the second panel.

Oscar Diez
  • 83
  • 1
  • 11