[]
This topic demonstrates how to use shortcut and mnemonic keys to access a menu by the keyboard instead of the mouse. You can apply shortcut and mnemonic keys to a menu item at design time or through code.
Add a C1MainMenu control to your form.
Right-click the C1MainMenu control, select Edit from its context menu, and click Ok. The default name for the menu is New Command.
Right-click the New Command item and select Properties from its context menu. In the Properties window for the C1CommandLink, expand the Command node, select the Shortcut property, and then select F6 from the Shortcut list box.
type=note
Note: The remaining steps are listed below for you to try and see how the short cut key functions.
Add a PictureBox control to your form.
Double-click New Command to create an event handler for the click event for New Command.
Within the event handler insert code to change the back color of the PictureBox to violet:
To write code in Visual Basic
If sender Is c1CommandMenu1 Then
Me.pictureBox1.BackColor = Color.Violet
End If
To write code in C#
if (sender == c1CommandMenu1)
{
this.pictureBox1.BackColor = Color.Violet;
}
Run the application and press the F6 key when the form appears. The picture box appears on the form.
In your source file locate the item in the menu where you want the shortcut key to exist.
Create a shortcut key for the C1CommmandMenu1 by entering the following code:
To write code in Visual Basic
Me.C1CommandMenu1.Shortcut = System.Windows.Forms.Shortcut.F6
To write code in C#
this.C1CommandMenu1.Shortcut = System.Windows.Forms.Shortcut.F6;