Ribbon for WinForms
キーボードのサポート
リボンの使用 > キーボードのサポート

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

    '太字ボタンのキーボードショートカットを設定します
    boldButton.ShortcutKeyDisplayString = "Bold"
    boldButton.ShortcutKeys = (Keys.Control Or Keys.B)

    '斜体ボタンのキーボードショートカットを設定します
    italicButton.ShortcutKeyDisplayString = "Italic"
    italicButton.ShortcutKeys = (Keys.Control Or Keys.I)

    '下線ボタンのキーボードショートカットを設定します
    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
public KeyboardShortcuts()
{
    InitializeComponent();

    //太字ボタンのキーボードショートカットを設定します
    boldButton.ShortcutKeyDisplayString = "Bold";            
    boldButton.ShortcutKeys = (Keys.Control | Keys.B);
   
    //斜体ボタンのキーボードショートカットを設定します
    italicButton.ShortcutKeyDisplayString = "Italic";
    italicButton.ShortcutKeys = (Keys.Control | Keys.I);

    //下線ボタンのキーボードショートカットを設定します
    underlineButton.ShortcutKeyDisplayString = "Underline";
    underlineButton.ShortcutKeys = (Keys.Control | Keys.U);

}
       
private void boldButton_Click(object sender, EventArgs e)
{
    richTextBox1.SelectionFont = new Font("Calibri", 12, FontStyle.Bold);
}

private void italicButton_Click(object sender, EventArgs e)
{
    richTextBox1.SelectionFont = new Font("Calibri", 12, FontStyle.Italic);
}

private void underlineButton_Click(object sender, EventArgs e)
{
    richTextBox1.SelectionFont = new Font("Calibri", 12, FontStyle.Underline);
}

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.

'ホーム・フォントタブのキーチップを設定します
homeTab.KeyTip = "H"
fontTab.KeyTip = "F"

'[ホーム]タブに太字・斜体・下線ボタンのキーチップを設定します
boldButton.KeyTip = "B"
italicButton.KeyTip = "I"
underlineButton.KeyTip = "U"

'[フォント]タブにFontComboBox・ColorPickerのキーチップを設定します
RibbonFontComboBox1.KeyTip = "T"
RibbonColorPicker1.KeyTip = "C"
//ホーム・フォントタブのキーチップを設定します
homeTab.KeyTip = "H";            
fontTab.KeyTip = "F";

//[ホーム]タブに太字・斜体・下線ボタンのキーチップを設定します
boldButton.KeyTip = "B";            
italicButton.KeyTip = "I";           
underlineButton.KeyTip = "U";

//[フォント]タブにFontComboBox・ColorPickerのキーチップを設定します
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.