Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleLet the user select a TabControl tab by pressing accelerator keys such as Alt-B in Visual Basic .NET
DescriptionThis example shows how to let the user select a TabControl tab by pressing accelerator keys such as Alt-B in Visual Basic .NET.
Keywordscontrols, TabControl, tab control, tabs, owner drawn, owner draw, TabDrawMode, OwnerDrawFixed, C#, C# programming, example, example program, Windows Forms programming
CategoriesControls, Graphics
 

A TabControl's tabs cannot display accelerator keys so the user cannot press Alt-X to open the X tab. In fact, the tabs cannot even display underlined characters. This example shows how to provide these features.

First make an owner-drawn TabControl that draws the tabs with underlined accelerator keys. (Note that this example always displays the accelerator keys underlined. Some operating systems only underline these keys after the user presses the Alt key.)

Next set the form's KeyPreview property to True. In the form's KeyDown event handler, look for the TabControl's accelerators and select the appropriate tabs. This example looks for Alt-B, Alt_L, and Alt-D.

 
' Look for Alt-B, Alt-L, and Alt-D.
Private Sub Form1_KeyDown(ByVal sender As System.Object, _
    ByVal e As System.Windows.Forms.KeyEventArgs) Handles _
    MyBase.KeyDown
    If (e.Alt) Then
        Select Case (e.KeyCode)
            Case Keys.B
                tabMenu.Focus()
                tabMenu.SelectedTab = tabPageBreakfast
                e.Handled = True
                e.SuppressKeyPress = True
            Case Keys.L
                tabMenu.Focus()
                tabMenu.SelectedTab = tabPageLunch
                e.Handled = True
                e.SuppressKeyPress = True
            Case Keys.D
                tabMenu.Focus()
                tabMenu.SelectedTab = tabPageDinner
                e.Handled = True
                e.SuppressKeyPress = True
        End Select
    End If
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated