1

I am making use of ContextMenuStrip in my program and apparently, it wont show its shortcut keys (mnemonics, those that should be shown as underlines under letters preceded by &) unless i press Alt, but when i press Alt, the shown ContextMenuStrip will hide because the main menu of the form will receive focus. Thus, in context menus, mnemonics are never seen!

Is there a way to force this behavior to be on for my program? I've read elsewhere that you can change it somewhere in the system settings, but i need people using my software to always see mnemonics, not require them globally changing their systems for my program to work correctly!

I have to show this menu via code in the KeyDown event handler when user presses Enter because its a popup for quick edit of a value represented by control. User clicks the control and can quickly change its contents. Think of it like in C# when you have a popup that pops on ctrl+space hinting possible code snipplets you can insert in this exact spot. So using it as a "context menu" property of a control or using keyboard "show context menu" button doesnt apply.

Thanks!

Istrebitel
  • 2,963
  • 6
  • 34
  • 49
  • That's how it should work. If you have a mnemonic on your top menu and press Alt (the key for that menu) your mnemonics will show up in the sub menus as well.. – Patrick Apr 15 '12 at 16:11
  • Mnemonics appear when you activate the menu with the keyboard. Use Shift+F10 for that, our use your keyboard's dedicated shortcut-menu key, if it has one. – Rob Kennedy Apr 15 '12 at 16:12
  • may be you're thinking of property for Shortcut Keys which you can find in the properties window as part of the designer. This will give you more options (like Shift and/or Ctrl, etc.). – coder Apr 15 '12 at 16:20
  • Yes but unfortunately this isnt a submenu but a context menu, it is shown by calling CMS.Show() inside Click() event handler of an object. If i press Alt, context menu is immediately hidden. – Istrebitel Apr 16 '12 at 12:33
  • Well there you go. You're displaying the menu as a result of a mouse click. Of course the accelerator characters won't show. They're not meant to; the user is using the mouse, not the keyboard, so there's no need to see keyboard shortcuts. Show the menu instead in response to a `wm_ContextMenu` message. That will fire for Shift+F10, right click, and the context-menu key. – Rob Kennedy Apr 16 '12 at 14:37
  • Well, i show it both on click and on Enter (when focus is on control showing the menu) - it doesnt matter. What do you mean by "in response to"? I need the menu to show on enter, because its just easier than presing shift+f10 – Istrebitel Apr 16 '12 at 14:56

2 Answers2

2

That is an operating system setting:

Control Panel\All Control Panel Items\Ease of Access Center\Make the keyboard easier to use\Make it easier to use keyboard shortcuts\Underline keyboard shortcuts and access keys.

Steve Wellens
  • 20,506
  • 2
  • 28
  • 69
0

Change the way the context menu is invoked. Don't show it manually, instead use something like:

textBoxSomething.ContextMenuStrip = yourContextMenuStrip;

In this case, if the user right-click on the text box (or other control you use), he will get the menu without mnemonics. But if he uses the keyboard context-menu-button to show the context menu, the mnemonics will be shown.

Arek
  • 1,276
  • 1
  • 10
  • 19
  • Unfortunately that is not possible (i have to open menu manually), but even if it would, please tell me how do i set the "context-menu-button"? when i assign a CMS to an object property, it only opens for me on right click – Istrebitel Apr 16 '12 at 12:34
  • Not sure, if I understand you correct. The context-menu-button is the button on your keyboard to show context menu. One of special Win buttons. No need to assign anything. Obviously it doesn't solve the problem when one right clicks with mouse, but wants to select the command be keyboard. – Arek Apr 16 '12 at 16:13
  • Ah i see. No, i'm using a context menu as a popup editor, so that button wont help. My program (part of it) is editing statements like "variable is equal to value" and user clicks or selects and presses "equal to" and a menu pops up with all possible optons like "greater than" and "not equal to" and user choses. So, i need to show it on click or on enter, not on "context menu button" that is present on the keyboard. – Istrebitel Apr 17 '12 at 09:12