How to Apply Keyboard Shortcuts

Shortcut keys can be executed by using a hidden menu strip.

Create a Menu Strip, add some menu items and assign some shortcut keys to the items.

01.png

Below are some of the examples that you can use to associate the menu items' shorcut key to the Ribbon Buttons.

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void ribbonButton1_Click(object sender, EventArgs e)
    {
        MessageBox.Show("Ribbon button 1 clicked");
    }

    private void ribbonButton2_Click(object sender, EventArgs e)
    {
        menuItem2ToolStripMenuItem.PerformClick();
    }

    private void ribbonButton3_Click(object sender, EventArgs e)
    {
        Function3();
    }

    private void Function3()
    {
        MessageBox.Show("Function 3 launched");
    }

    private void menuItem1ToolStripMenuItem_Click(object sender, EventArgs e)
    {
        ribbonButton1.PerformClick();
    }

    private void menuItem2ToolStripMenuItem_Click(object sender, EventArgs e)
    {
        MessageBox.Show("Menu Item 2 clicked.");
    }

    private void menuItem3ToolStripMenuItem_Click(object sender, EventArgs e)
    {
        Function3();
    }
}

Last edited Jun 1, 2012 at 3:24 AM by adriancs, version 4

Comments

No comments yet.