I’m working on an application which uses numerous panels which are swapped at runtime. The swapping of the panels is controlled by handling keydown events and examining the current “state” of the application to determine how to route the keys.
I was doing some cleanup work in the form designer moving panels and labels around and now i’ve somehow disabled my main form’s ability to pick up the tab key in my keydown event. I still get all other keys, including enter key.
The code didn’t change and was very much tested to function fine with a tab key, so I can only imagine I accidentally turned off some important property when playing in the designer.
I have keypreview turned on in my main form. Since I get other key events I do not believe that my keydown handler is working incorrectly. Somehow my form just stopped feeding tab key through. TabIndexes are sequentially numbered but they should not matter since I am using keypreview to process the event before letting tabindex determine its next jump.
I figured this might be an easy one for somebody who’s been there and fought this before. I have backups with the tab key still functioning but i’ve made leaps today in the logic so i’m not quite ready to roll back or do a side-by-side compare of every object on the form.
That’s not supposed to work. And won’t when you have any controls on the form that can get the focus. The Tab key and the cursor keys are used for navigation, moving the focus from one control to another.
The KeyPreview property is a VB6 legacy compatibility property, used to implement custom shortcut keystrokes. The code that intercepts the navigation keys runs before the code that fires the form’s KeyDown event. You instead should override the ProcessCmdKey() method, it runs before the navigation code so can see the Tab and cursor keys: