0

There are too many items in the menu strip item.
Like this:

Long menu dropdown

It looks very long and bad. I want to add a scroll bar to menu strip items.
I want to see 3 of these items with the help of the scroll bar.
How can I do it?

Jimi
  • 29,621
  • 8
  • 43
  • 61
huseyin
  • 63
  • 7
  • Does this answer your question? [Add vertical scroll bar to panel](https://stackoverflow.com/questions/6090558/add-vertical-scroll-bar-to-panel) – dt170 May 04 '20 at 13:53
  • From a UX perspective this actually makes it worse, as you've increased the time to do basically everything with that menu. Basically even worse than the adaptive menus of Office 2000. The intention was to hide complexity and make things appear simpler/easier, but it backfired. So if the number of items is your problem, reduce the number of items, distribute to different menus or sub-menus (those are a problem in itself as well, though), but don't try to make it seem like there are fewer items. – Joey May 04 '20 at 16:49
  • Please post what you've tried already and what research you've done to make this work. This appears to be a duplicate of what @dt170 posted as well. – Nik P May 04 '20 at 19:48
  • @dt170 What you say is not adapted to my situation, thanks – huseyin May 04 '20 at 21:00
  • @NikP I had no idea what to do, I don't have an existing code, I wanted to learn how to improve its appearance. – huseyin May 04 '20 at 21:04
  • 1
    Try to use the code in the answer @dt170 linked to to figure out how that solution works, and then adapt the concept to your situation. From your question, it looks like the answer. I also see another answer on this post that might help you out. – Nik P May 04 '20 at 21:54

1 Answers1

0

You can set the maximum height of a MenuItem's DropDown using the ToolStripMenuItem.DropDown MaximumSize property.

You can determine the height of the DropDown based on the maximum number of Items you want to show. Or any other measure that makes sense in your scenario (maybe a measure that fits the current ClientSize.Height of a Form).

To specify a height relative to a maximum number of sub items (here, maxSubMenuItems), sum the Height of the first maxSubMenuItems sub items and use this measure to set the MaximumSize property.

The standard (top and bottom) scroll buttons will appear.

Here, I'm using a maxHeight + (maxHeight / maxSubMenuItems) value, to add some space, at the top and bottom of the dropdown, otherwise a menu may not fit in and it also looks better :)

Insert this code in the Form's Constructor (after InitializeComponent()) or in Form.Load:

int maxSubMenuItems = 6;

if (toolStripMenuItem1.DropDownItems.Count > maxSubMenuItems) {
    int maxHeight = toolStripMenuItem1.DropDownItems
        .OfType<ToolStripMenuItem>()
        .Take(maxSubMenuItems)
        .Sum(itm => itm.Height);

    toolStripMenuItem1.DropDown.MaximumSize = 
       new Size(toolStripMenuItem1.DropDown.Width, maxHeight + (maxHeight / maxSubMenuItems));
}

► This can come in handy when you have to show a list of sub-items that represent Fonts, for example. So you may want to show a string drawn using the Font name in the list. Or similar situations, when you have to present a single, potentially long, dropdown.

In other cases, try to limit the number of items per ToolStripMenuItem using sub menus.

Jimi
  • 29,621
  • 8
  • 43
  • 61