1
votes

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.

2

2 Answers

2
votes

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:

Protected Overrides Function ProcessCmdKey(ByRef msg As Message, keyData As Keys) As Boolean
    If keyData = Keys.Tab Then
        '' Do something, preferably navigation related since that what the user expects
        ''...
        Return True   '' That means that the key was consumed
    End If
    Return MyBase.ProcessCmdKey(msg, keyData)
End Function
0
votes

I searched for tabstop and looked for an object with this as true.

My "find" in VS didn't find anything but then I saw a listbox on the last panel I added to my project that had tabstop turned on.

Turning this off got me back to where I originally was at with my code picking up the tab key.