winformsmenustrip

Getting the Left and Right arrow keys to select the previous/next menu instead of the next/previous menu


Noticed in a full application, but fully reproducable in a simple demo:

I've got a MenuStrip containing three menus, A, B, and C. Each of these menus contains three items, A1/A2/.../C2/C3.

When I press Alt, the first menu A becomes selected. I can then use the and keys to select other menus. That is as it should be.

However, when I press to open a menu, I can still use and to select other menus, but the order is reversed: selects the next menu, and the previous.

I'm having trouble figuring out if something is wrong with my local system, if this is a bug in the MenuStrip component, or if I am forgetting to set a required property. All three seem strange to me, because in all three cases I would expect someone to have encountered this problem already, and I cannot even find anyone else asking about this.

If it's not clear what I'm asking, here is an image:

Menu strip problem

And before I forget to mention, there is no relevant code. This demo application is a brand new WinForms project, has one MenuStrip control added to its default form, and has got three menus with three items each, for each of which I have set nothing more than the text.


Solution

  • This is a bug/misfeature in MenuStrip.

    Looking at the ToolStripDropDown.ProcessArrowKey implementation with Reflector shows that the arrow keys get reversed depending on SystemInformation.RightAlignedMenus. That's not right. It should depend on the right-to-left mode of the menu strip itself, which may sometimes (usually?) match SystemInformation.RightAlignedMenus, but not always, and not on my system.

    SystemInformation.RightAlignedMenus is user-configurable via Control Panel, Tablet PC Settings, Other, Handedness, and indeed if I change that to Left-handed, I get the menus to behave correctly. The default and correct setting for me is Right-handed. Since the MenuStrip component is simply not keyboard-usable on my system, I will replace my use of it with a standard MainMenu component.

    Update: I'm actually using a derived control to be able to provide nice menu images. It is based on the Microsoft sample on "Visual Style Menus". A more fully-featured implementation that also works on Windows XP and prior (in that case using owner-drawn menus) is available at Vista Menu with Icons in C#, but that is more complicated than necessary for me.