问题
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?
回答1:
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
回答2:
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.
来源:https://stackoverflow.com/questions/4726551/can-a-menustrip-control-have-its-layoutstyle-set-to-stackwithoverflow