Work with Ribbon / Keyboard Support
Keyboard Support

The C1Ribbon control supports keyboard shortcuts. You can perform tasks quickly by simply pressing a few keys. The user can access every command in the Ribbon using a key. For instance, to make the text bold, you can use the combination of Ctrl and B keys.

Note: This topic assumes that you have added a Ribbon button to the group and created a RibbonButton.Click event handler for the Bold button.

Complete the following steps for keyboard shortcuts.

  1. Change the Windows Form to Ribbon Form.
  2. Select the Ribbon button (in this case, the Bold button) to display its properties in the Properties window.
  3. Locate the ShortcutKeys property and select the Ctrl check box and select B from the drop-down list.
    locate shortcut key property
  4. Click outside the Shortcut Keys editor to accept the changes. Save and run the application.
    Now when you run the application, pressing the CTRL+B key combination will trigger the RibbonButton.Click event for the Bold button and make the selected text bold in style.

You can also add keyboard shortcuts to the Ribbon control programmatically using the ShortcutKeyDisplayString and ShortcutKeys properties of RibbonButton class.

Private Sub KeyboardShortcuts_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    'Set Keyboard shortcut for Bold button
    boldButton.ShortcutKeyDisplayString = "Bold"
    boldButton.ShortcutKeys = (Keys.Control Or Keys.B)

    'Set Keyboard shortcut for Italic button
    italicButton.ShortcutKeyDisplayString = "Italic"
    italicButton.ShortcutKeys = (Keys.Control Or Keys.I)

    'Set Keyboard shortcut for Underline button
    underlineButton.ShortcutKeyDisplayString = "Underline"
    underlineButton.ShortcutKeys = (Keys.Control Or Keys.U)
End Sub


Private Sub boldButton_Click(sender As Object, e As EventArgs) Handles boldButton.Click
    RichTextBox1.SelectionFont = New Font("Times New Roman", 12, FontStyle.Bold)
End Sub

Private Sub italicButton_Click(sender As Object, e As EventArgs) Handles italicButton.Click
    RichTextBox1.SelectionFont = New Font("Times New Roman", 12, FontStyle.Italic)
End Sub

Private Sub underlineButton_Click(sender As Object, e As EventArgs) Handles underlineButton.Click
    RichTextBox1.SelectionFont = New Font("Times New Roman", 12, FontStyle.Underline)
End Sub

Adding KeyTips to Ribbon Items

KeyTips, also known as access keys or accelerators are single letter or number displayed below or next to a Ribbon tab, command or drop-down menu. They can be used as shortcut key combinations to access or activate control. The C1Ribbon control supports KeyTips, with which you can display all the commands on the Ribbon. It allows you to move between elements on the C1Ribbon control using keyboard commands.

In order to see KeyTips for each command, the user can press and release the ALT or F10 key.

The image below illustrates the KeyTips for Home and Font tabs:

key tips example

You can set the KeyTip for all the Ribbon items using KeyTip property of the RibbonButton class. The following code snippet illustrates adding KeyTips for the Ribbon items.

'Set Keytip for Home/Font Tab
homeTab.KeyTip = "H"
fontTab.KeyTip = "F"

'Set Keytip for Bold/Italic/Underline button in Home tab
boldButton.KeyTip = "B"
italicButton.KeyTip = "I"
underlineButton.KeyTip = "U"

'Set Keytip for FontComboBox/ColorPicker in Font tab
RibbonFontComboBox1.KeyTip = "T"
RibbonColorPicker1.KeyTip = "C"
Note: KeyTip should always be set in the order of Ribbon elements hierarchy. That is, you need to set the KeyTip property for the Tab group before setting the KeyTip for the Ribbon element inside that group.