Guide of KetticShortcuts for Menu Items in C#.NET
The shortcuts component supports the modifier keys, multiple keys shortcuts, as well as Shortcuts without modifier keys. The modifier keys support allows you use the Ctrl, Alt and Shift keys as shortcuts, The multiple keys support allows you use more than one keys like Alt + X as the shortcuts, and Shortcuts without modifier keys allows you set others keys as shortcut, however, cautions may be needed to avoid the conflict with other control. Each shortcut uses the same object model and class hierarchy.
C# Tutorial Create Menu Items with Shortcuts control
- Open an existing .NET project or create a new one in your Microsoft Visual Studio.
- Drag a KetticMenu control from the toolbox and drop it on the form
- Create a menu item object ketticMenuItem1. This is achieved by entering New on the Type Here on KetticMenu
- Open the dropdown menu via clicking the ketticMenuItem1 to create a submenu item, and name it as ketticMenuItem2
- Locate Click events for ketticMenuItem1 and ketticMenuItem2 in the Properties Window, and then create event handlers for them
- Copy and paste the following C# code to the event handlers respectively
void ketticMenuItem1_Click(object sender, EventArgs e)
void ketticMenuItem2_Click(object sender, EventArgs e)
- Add the shortcuts to the items as your requirements with the C# code below.
this.ketticMenuItem1.Shortcuts.Add(new KetticShortcut(Keys.Control, Keys.N));
this.ketticMenuItem2.Shortcuts.Add(new KetticShortcut(Keys.Shift, Keys.F, Keys.K));
- Run the application and the shortcuts will be shown for the KetticMenuItems automatically
- Additionally, we can add custom text to the shortcuts that we just added. This is achieved through setting the HintText property of the menu item with the C# code below.
ketticMenuItem2.HintText = "Custom Text";