ComponentOne Menus and Toolbars for WinForms
Applying ShortCut Keys to Menus
Menus and Toolbars for WinForms Task-Based Help > Menu Tasks > Applying ShortCut Keys to Menus

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.

To add a shortcut key to a menu item at design time

  1. Add a C1MainMenu control to your form.
  2. Right-click the C1MainMenu control, select Edit from its context menu, and click Ok. The default name for the menu is New Command.
  3. 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.
    Note: The remaining steps are listed below for you to try and see how the short cut key functions.
  4. Add a PictureBox control to your form.
  5. 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

    Visual Basic
    Copy Code
    If sender Is c1CommandMenu1 Then
            Me.pictureBox1.BackColor = Color.Violet
    End If
    

    To write code in C#

    C#
    Copy Code
    if (sender == c1CommandMenu1)
            {
                    this.pictureBox1.BackColor = Color.Violet;
            }
    
  6. Run the application and press the F6 key when the form appears. The picture box appears on the form.

To add a shortcut key to a menu item programmatically

  1. In your source file locate the item in the menu where you want the shortcut key to exist.
  2. Create a shortcut key for the C1CommmandMenu1 by entering the following code:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Me.C1CommandMenu1.Shortcut = System.Windows.Forms.Shortcut.F6
    

    To write code in C#

    C#
    Copy Code
    this.C1CommandMenu1.Shortcut = System.Windows.Forms.Shortcut.F6;
    
See Also