PRB: Can't Get Tabstrip Control to Support Hot-Key Activation

Last reviewed: February 12, 1996
Article ID: Q129894
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0

SYMPTOMS

When a Microsoft Tabstrip Control is used in a program, you cannot activate it by using hot keys. The control allows you to underline characters in the captions on the tabs by using the ampersand (&) character, but this doesn't enable a hot key that will activate the tab. This behavior is by design.

RESOLUTION

If you want the tabs to be activated by hot keys, use the following method. To be able to use the Tabstrip control, you need to make sure the 'Windows Common Controls' control is included in your project.

Steps to Create Tabstrip with Hot-Keys

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. Set the KeyPreview property of Form1 to True in the Properties window.

  3. Add a Tabstrip (TabStrip1) to the form.

  4. Double-click the Custom property of the Tabstrip in the Properties window to bring up the Tabstrip Control Properties window.

  5. In the tabs section of the Tabstrip Control Properties window, add three tabs with the following captions: &First, &Second, and &Third.

  6. Close the Tabstrip Control Properties window by clicking the OK button.

  7. Add the following code to the KeyDown event of the form:

          If Shift = 4 Then
    
             Select Case KeyCode
                Case Asc("f"), Asc("F")
                   TabStrip1.Tabs(1).Selected = True
                   KeyCode = 0
                Case Asc("s"), Asc("S")
                   TabStrip1.Tabs(2).Selected = True
                   KeyCode = 0
                Case Asc("t"), Asc("T")
                   TabStrip1.Tabs(3).Selected = True
                   KeyCode = 0
             End Select
          End If
    
    

  8. Press the F5 key to run the program. Notice that as you press ALT-F, ALT-S, or ALT-T, the appropriate tab is selected.

STATUS

This behavior is by design. The Microsoft Tabstrip functions the way it does in order to preserve system resources. As you use this control, you will notice that it is missing other features that third-party tab controls provide. This gives you, the programmer, better control over your system. You can implement only those features that you really need and not waste valuable system resources on features you don't need.


Additional reference words: 4.00 vb4win vb4all
KBCategory: kbprg kbcode kbprb
KBSubcategory: PrgCtrlsCus


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 12, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.