none
Shortcut key or hot key for tab control RRS feed

  • Question

  • Hi,

    I have upgraded my project from vb6 to vb.net, the text for the tab page displays with '&' symbol. The char next to the '&' symbol is not functioning as the hot key. Also, there is no option or property in the 'Tabpage collection editor'.

    In some other forums i could see some code to that but it is not working, also the nemonic code, TabControlEx is also not working.

    So, what can i do? Is shortcut key is possible in .Net? Is there any easy way to achieve this?

    Any help is highly appreciated.


    Thanks, Karthikeyan.V

    Thursday, June 21, 2012 12:34 PM

Answers

  • Thank you Rohit, MikeFeng and Cor Ligthert for your over whelming responses...

    After having a look at all your links and few other forumns, i have implemented the required functionality as follows..

    Created 2 functions as below,

    Private Sub DrawOnTab(ByVal sender As Object, ByVal e As DrawItemEventArgs)

            Dim objGraphics As Graphics = e.Graphics
            Dim objStringFormat As New StringFormat()
            objStringFormat.HotkeyPrefix = Drawing.Text.HotkeyPrefix.Show
            objStringFormat.FormatFlags = StringFormatFlags.NoWrap
            objGraphics.DrawString(tabSettings.TabPages(e.Index).Text, tabSettings.Font, SystemBrushes.WindowText, tabSettings.GetTabRect(e.Index), objStringFormat)
            objGraphics.Dispose()
    End Sub

        Protected Overrides Function ProcessMnemonic(ByVal charCode As Char) As Boolean
            Dim objTabPage As TabPage
            For Each objTabPage In tabSettings.TabPages
                If Control.IsMnemonic(charCode, objTabPage.Text) Then
                    tabSettings.SelectedTab = objTabPage
                    tabSettings.Focus()
                    Return True
                End If
            Next
            Return False
        End Function

    Added the following lines in the form_load where i have the tabs..

    Private Sub frmOptions_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
           
            tabSettings.DrawMode = TabDrawMode.OwnerDrawFixed
            AddHandler tabSettings.DrawItem, AddressOf DrawOnTab
       
    End Sub

    This made it :) 

    Thanks for your esponses.


    Thanks, Karthikeyan.V

    • Marked as answer by icewar_karthi Friday, June 22, 2012 9:27 AM
    Friday, June 22, 2012 9:27 AM

All replies

  • May be you can tweak through using PreviewKeyDown event of TabControl.

    Mark Answered, if it solves your question and Vote if you found it helpful.
    Rohit Arora

    Friday, June 22, 2012 8:20 AM
  • Hi Icewar,

    Welcome to the MSDN Forum.

    Please take a look at this KB: http://support.microsoft.com/kb/839201/en 

    This article describes how to capture keyboard events in the Form object by using Microsoft Visual Studio .NET. The sample function demonstrates how to confirm that a user has entered a keyboard shortcut.

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, June 22, 2012 8:49 AM
    Moderator
  • Icewar,

    The windows form is not the base class from .Net, I always think that those who think that are those who answer in this forum questions for that. 

    This is the Base Class 

    http://msdn.microsoft.com/en-us/library/system.object.aspx 

    There is much more direct related to that then you see on that page.

    However, the Tab control is that not direct, it is a windows forms class (it was all there was in VB6 so I understand your confusion)

    There is a special windows forms forum.

    http://social.msdn.microsoft.com/Forums/en-US/winforms/threads

    Also is this often done in the general forum for VB (as you write VB6 I assume you are doing that)

    http://social.msdn.microsoft.com/Forums/en-US/vbgeneral


    Success
    Cor

    Friday, June 22, 2012 9:03 AM
  • Thank you Rohit, MikeFeng and Cor Ligthert for your over whelming responses...

    After having a look at all your links and few other forumns, i have implemented the required functionality as follows..

    Created 2 functions as below,

    Private Sub DrawOnTab(ByVal sender As Object, ByVal e As DrawItemEventArgs)

            Dim objGraphics As Graphics = e.Graphics
            Dim objStringFormat As New StringFormat()
            objStringFormat.HotkeyPrefix = Drawing.Text.HotkeyPrefix.Show
            objStringFormat.FormatFlags = StringFormatFlags.NoWrap
            objGraphics.DrawString(tabSettings.TabPages(e.Index).Text, tabSettings.Font, SystemBrushes.WindowText, tabSettings.GetTabRect(e.Index), objStringFormat)
            objGraphics.Dispose()
    End Sub

        Protected Overrides Function ProcessMnemonic(ByVal charCode As Char) As Boolean
            Dim objTabPage As TabPage
            For Each objTabPage In tabSettings.TabPages
                If Control.IsMnemonic(charCode, objTabPage.Text) Then
                    tabSettings.SelectedTab = objTabPage
                    tabSettings.Focus()
                    Return True
                End If
            Next
            Return False
        End Function

    Added the following lines in the form_load where i have the tabs..

    Private Sub frmOptions_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
           
            tabSettings.DrawMode = TabDrawMode.OwnerDrawFixed
            AddHandler tabSettings.DrawItem, AddressOf DrawOnTab
       
    End Sub

    This made it :) 

    Thanks for your esponses.


    Thanks, Karthikeyan.V

    • Marked as answer by icewar_karthi Friday, June 22, 2012 9:27 AM
    Friday, June 22, 2012 9:27 AM