Can a MenuStrip control have its LayoutStyle set to StackWithOverflow?
Asked Answered
E

2

5

I create a simple form with a MenuStrip. The MenuStrip's LayoutStyle is set to HorizontalStackWithOverflow (the default).

According to the MSDN reference on MenuStrip, its LayoutStyle property is inherited from ToolStrip. One of the possible values for the LayoutStyle is HorizontalStackWithOverflow which is also the default setting. This setting should provide items with its Overflow property set to AsNeeded are moved to an overflow button.

When I run the application and resize the form so the menu won't fit completely, this doesn't happen. I've set my ToolStripMenuItems Overflow property to AsNeeded, but when I resize the form, the menu items on the right just disappear.

Is the documentation wrong and can you only get an overflowbutton on a ToolStrip and not on a MenuStrip? Or is there something else I have to do in order to get things working? Or am I just misreading the documentation?

Ento answered 18/1, 2011 at 16:39 Comment(0)
H
8

I just had the same problem, and found a way to get it working.

On the MenuStrip you need to set:

myMenuStrip.CanOverflow = True

The default is false.

Then for each MenuItem you need to set:

myToolStripMenuItem.Overflow = ToolStripItemOverflow.AsNeeded

or

myToolStripMenuItem.Overflow = ToolStripItemOverflow.Always

The default is ToolStripItemOverflow.Never

References:

MenuStrip.CanOverflow

ToolStripMenuItem.Overflow

Humoral answered 14/10, 2011 at 0:26 Comment(1)
It works: myMenuStrip.CanOverflow = True is really the key. @comecme: consider marking as accepted answer.Skillern
A
6

The ToolStrip classes have plenty of hairs like this. I think the appropriate selection here is LayoutStyle = Flow to get the menu items wrapped. This is the way the built-in Windows menus work.

You do however have to take care of the layout problem this causes. Put a Panel on the form with Dock = Fill so that all controls automatically move down when the menu strip needs more space.

Agonic answered 18/1, 2011 at 16:58 Comment(2)
With LayoutStyle=Flow at least the menu items don't disappear anymore. But you you're saying is it isn't possible to use an OverflowButton on a MenuStrip? So either the documentation is wrong or it is a bug?Ento
Not sure it matters, it just doesn't work. I'm 95% sure you can't make it work. You could file a feedback report at connect.microsoft.com. They have however been closing Winforms bug reports for the past couple of years with "won't fix". You have a good workaround, I recommend you use it.Agonic

© 2022 - 2024 — McMap. All rights reserved.