How to Use Key Combinations in VB.NET

Written by alexander gokhfeld
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Use Key Combinations in VB.NET
Windows Forms key combinations allows users to create custom shortcuts. (Jupiterimages/ Images)

Microsoft Visual Basic for .NET (VB.NET) programming language gives programmers the ability to control data input in the Windows Forms. By using VB.NET program controls you can capture any single keystroke or key combinations, including the "Ctrl" and "Alt" keys. The key combinations are available in addition to the Windows Forms standard keys, that are displayed as underscored letters in menus or menu items used with the "Alt" key. By using the key combinations in VB.NET programs you can create custom key shortcuts on the Windows Forms.

Skill level:


  1. 1

    Click "Start," "Microsoft Visual Basic for .NET."

  2. 2

    Click "File," "Open." Double-click on the Visual Basic program in which you want to define a new key combination.

  3. 3

    Enter the following code after the "public void DataGrid" line in the program:

    Class MyDataGrid

    Inherits DataGrid
    Protected Overrides Function ProcessCmdKey( _
        ByRef msg As Message, _
        ByVal key Data As Keys _
                                ) As Boolean
    End Function

    MenuItem.ShortcutKeys = Keys.Control Or Keys.P

    End Class

    to define the "Ctrl+P" key combination on your Windows Forms.

  4. 4

    Click "File," "Save" and "OK" to add the "Ctrl+P" key combination to your VB.NET program.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.