Effective way of (on a tabcontrol) tabbing through controls automatically pages through TabControl.tabs

StackOverflow https://stackoverflow.com/questions/4688896

Pergunta

I've tried editing this to differentiate between 'tabs' on a tabControl and 'tabbing' through controls with the tab key, but I'm just going to power through and hope the meaning is clear....

I have a c# project with an interface featuring a tabcontrol. 3 tab pages (PersonalInformation, ContactDetails, AdditionalNotes) and the relevant controls are contained within each tab.

Most of our users find it easier to navigate interfaces using the keyboard only (such as keyboard shortcuts and tabbing through controls for navigation). I've included keyboard listeners for various shortcut combinations. For example, PageUp and PageDown will allow users to page through the various tabs.

However, these users follow the same pattern for entering information: once they've tabbed through the PersonalInformation tab's controls (populating as need be) and reached the last control on the tab, they wish to 'keep tabbing'. As in: when last control focussed on TabControl.Page1, a user pressing tab will move focus to the first control on TabControl.Page2. When last control focussed on TabControl.Page2, a user pressing tab will move focus to TabControl.Page3.

In this way the information is grouped and contained together and users can simply keep typing and tabbing to enter all the information on the form, all without needing the keyboard.

So the real question is doing this effectively: I can't just simply handle the OnLeave of the last control: a user (on the last control) selecting an earlier control (or even shift-Tab) would also fire the event.

Another problem is maintenance: Adding another control at the bottom of the tab could throw the whole thing off if the maintainer forgets/doesnt know that this 'move focus to next tab' feature. Perhaps getting the last control added to the form?

Foi útil?

Solução

I've overridden the ProcessDialogKey method to handle the Tab (and Shift+Tab) keystrokes, shifting tabPages and focus to the relevant controls. Functionally speaking, this will work.

Maintenance issues

  • This particular interface doesn't change often and there's still a fair amount of usability testing underway to determine what works best before its released (so we may end up reverting).

  • The bad thing is that shifting focus is pretty hard-coded. I don't see any particular easy way of handling this generically.

  • Fortunately, maintenance should be low as there's only 3 tabPages. The business logic is completely encapsulated elsewhere so there's no risk to business functions. Code contained within relevant regions so its easy to spot. Its also a pretty quick thing to spot going wrong as the users are 'keyboard enthusiasts' and tab through everything during data entry.

    Any comments/suggestions are still welcome.

  • Licenciado em: CC-BY-SA com atribuição
    Não afiliado a StackOverflow
    scroll top