Shortcuts in .Net, Winforms, VB

From Shortcuts Wiki
Jump to: navigation, search

Here is how to create some shortcuts in .Net, Winforms, VB.

Create a WinForm[edit]

Create a new WinForm (with Visual Studio : menu>project>Add new item...>Winform).

In the properties editor, you don't need to set its KeyPreview property to true.

Override the ProcessCmdKey method[edit]

In the winform code, override (redefine) the ProcessCmdKey method. Inside, test the second parameter of type Keys to know which keys were pressed. Return true if processed, if not, call the parent method.

Example :

 Protected Overrides Function ProcessCmdKey(ByRef msg As Message, keyData As Keys) As Boolean
   If keyData = (Keys.Control Or Keys.C) Then
     'do copy something
     Return True
   End If
   Return MyBase.ProcessCmdKey(msg, keyData)
 End Function

More informations[edit]