Domanda

I have two questions regarding the windows form menu strip:

1. How to force the form to always show the helper keys? Currently the letter underlines are displayed only if the Alt key is pressed.

2. What is the command to cause a menu to drop down? Usually a menu drops down after the user clicks the menu button or navigates it with the keyboard, but I want to cause a menu to drop down by pressing an interface button and I can't figure out how to do it. I tried fiddling the DropDown property, but it didn't help.

È stato utile?

Soluzione

  1. With ToolStripMenuItem there are three properties you need to look at: ShortcutKeyDisplayString ShortcutKeys ShowShortcutKeys

    • Although the three apply to the root menu item, say File or Help, you will not be able to see the short cuts, however you should be able to enable the ShortcutKeys, set ShowShortcutKeys to true and without modifying ShortcutKeyDisplayStringhave them appear next to sub ToolStripMenuItem's.
  2. The method you are looking for on ToolStripMenuItem is ShowDropDown(), executing this method will drop down the menu.

Example:

((ToolStripMenuItem)FileMenu.Items[0]).ShowDropDown();

Altri suggerimenti

  1. AFAIK, it is not easily possible to do that in C#. The easiest way is to change the Windows settings. On Windows 7:
    • Go to Control panel
    • Ease of Access Center
    • Make the Keyboard easier to use
    • Check Underline keyboard shortcuts and access keys.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top