Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a MenuStrip control have its LayoutStyle set to StackWithOverflow?

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?

like image 589
comecme Avatar asked Jan 18 '11 16:01

comecme


2 Answers

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

like image 113
Glenn Avatar answered Nov 02 '22 22:11

Glenn


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.

like image 40
Hans Passant Avatar answered Nov 03 '22 00:11

Hans Passant