Question adding shortcut to contextmenustrip programmatically

Zexor

Well-known member
Joined
Nov 28, 2008
Messages
520
Programming Experience
3-5
VB.NET:
Private Sub cmsTypes_Opening(sender As Object, e As CancelEventArgs) Handles cmsTypes.Opening

With cmsTypes.Items       
        .Add("Cut", Nothing, AddressOf cmsTypes_Click)
        .Add("Paste", Nothing, AddressOf cmsTypes_Click)
 End With
        e.Cancel = False
End Sub

This will just have Cut and Paste on the contextmenu, how do i add the Ctrl+X and Ctrl+V to the menu?
 
Solution
VB.NET:
.Add(New ToolStripMenuItem("Cut", Nothing, AddressOf cmsTypes_Click, Keys.Control Or Keys.X))
.Add(New ToolStripMenuItem("Paste", Nothing, AddressOf cmsTypes_Click, Keys.Control Or Keys.V))
That code specifies the shortcut keys and they will be displayed on the menu item by default. You should read the documentation for the ToolStripMenuItem class and then you'll see the relevant properties and this constructor.
VB.NET:
.Add(New ToolStripMenuItem("Cut", Nothing, AddressOf cmsTypes_Click, Keys.Control Or Keys.X))
.Add(New ToolStripMenuItem("Paste", Nothing, AddressOf cmsTypes_Click, Keys.Control Or Keys.V))
That code specifies the shortcut keys and they will be displayed on the menu item by default. You should read the documentation for the ToolStripMenuItem class and then you'll see the relevant properties and this constructor.
 
Solution

Latest posts

Back
Top