How to Use Key Combinations in VB.NET

How to Use Key Combinations in VB.NET thumbnail
Windows Forms key combinations allows users to create custom shortcuts.

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.

Instructions

    • 1

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

    • 2

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

    • 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 keyData 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

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

Related Searches:

References

  • Photo Credit Jupiterimages/Photos.com/Getty Images

Comments

You May Also Like

Related Ads

Featured