Can a MenuStrip control set its LayoutStyle to StackWithOverflow?

I am creating a simple form using MenuStrip. MenuStrip LayoutStyle set to HorizontalStackWithOverflow (default).

According to the MSDN link to MenuStrip, its LayoutStyle is inherited from ToolStrip. One possible value for LayoutStyle is HorizontalStackWithOverflow , which is also the default setting. This parameter should provide elements with the Overflow property set to AsNeeded to move to the overflow button.

When I launch the application and resize the form so that the menu does not completely fit, this does not happen. I set the Overflow ToolStripMenuItems property to AsNeeded, but when I resize the form, the menu items on the right disappear.

Incorrect documentation, and you can only get the overflow of the ToolStrip button, and not in the MenuStrip? Or is there something else I have to do to make everything work? Or am I just reading the documentation wrong?

+4
source share
2 answers

I had the same problem and I found a way to make it work.

In MenuStrip you need to install:

 myMenuStrip.CanOverflow = True 

The default value is false.

Then for each MenuItem you need to install:

 myToolStripMenuItem.Overflow = ToolStripItemOverflow.AsNeeded 

or

 myToolStripMenuItem.Overflow = ToolStripItemOverflow.Always 

The default is ToolStripItemOverflow.Never

Literature:

MenuStrip.CanOverflow

ToolStripMenuItem.Overflow

+7
source

There are many such hairs in ToolStrip classes. I think the appropriate choice here is LayoutStyle = Flow to get the menu items wrapped. This is the way Windows built-in menus work.

However, you must take care of the layout problems that this causes. Place the panel on the form with Dock = Fill so that all controls automatically move down when the menu bar requires more space.

+6
source

Source: https://habr.com/ru/post/1336012/


All Articles