12

I want to be able to show the hotkey combination assigned to a toolstrip menu item in winforms. For instane, in any program (even your browser settings menu) you can see various menu items, and generally, aligned to the right of their item, is their hotkey shortcut. I want to do this programmatically.

Example: Instead of typing

Open a file                         (ctrl+O)

I want to have the properties show up independently of each other.

How can I achieve this?

2

1 Answer 1

14

You want to you use the ShortcutKeys property of the ToolStripMenuItem. This will let you pick the particular key combination you want for each menu item and it will show up to the right of the menu item. Make sure that you have ShowShortcutKeys property of the ToolStripMenuItem set to true.

4
  • 5
    It appears that ShortcutKeyDisplayString was the property I needed to use.
    – jwarner112
    Commented Oct 14, 2013 at 12:00
  • The ShortcutKeyDisplayString only sets the text. The ShortcutKeys property sets the actual short cut key for the user to use. The DisplayString is just for show so if you don't use ShortcutKeys the user's action to what you show in DisplayString will not work. Commented Oct 14, 2013 at 18:21
  • Yes, though I've already handled the actual shortcut interpretation, I just needed the text. No matter, you're getting Best Answer!
    – jwarner112
    Commented Oct 15, 2013 at 13:22
  • 1
    To add, I was trying to set shortcut keys on a ToolStripMenuItem that has children, however this did not work. Removing the child items worked.
    – Slate
    Commented May 16, 2018 at 13:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.