3

First, a little overview of how my current UI looks like:

Current UI

Note that other than the stuff in the ToolStripControlHost, everything else is standard WinForms.

In short, I want to have something similar to the ToolStripControlHost but I need it "pinned" to the bottom of the menu, mostly so that when there is a lot of items, it is not scrolled like the rest of the menu items.

After some searching around I came to the conclusion that maybe customizing painting might be the solution, don't know if this is the case though.

Here's some sample code, but I'm not sure how useful it is:

public ToolStripDropDownButtonContainer(ToolStripDropDownButton button)
{
    this.UIControl = button.GetCurrentParent();
    this.Button = button;

    if (this.Button.Tag == null)
    {
        this.Button.Tag = true;

        this.Button.DropDownDirection = ToolStripDropDownDirection.AboveLeft;
        ToolStripDropDownMenu menu = (ToolStripDropDownMenu)this.Button.DropDown;

        menu.SuspendLayout();
        try
        {
            menu.BackColor = Color.White;
            menu.ShowImageMargin = false;
            menu.ShowCheckMargin = false;
            menu.AutoSize = true;
            menu.Margin = Padding.Empty;
            menu.Padding = Padding.Empty;
            menu.GripMargin = Padding.Empty;
            menu.GripStyle = ToolStripGripStyle.Hidden;
            menu.MinimumSize = new Size(310, 0);
            menu.MaximumSize = menu.MinimumSize;
            // TODO pin panel (or some control) to the bottom-side of the menu
        }
        finally
        {
            menu.ResumeLayout();
        }
    }
}
Christian
  • 27,509
  • 17
  • 111
  • 155
  • Did I understand correctly: you are looking to have 2 "areas" in the popup: the top where the 3-4 things scroll and one anchored to the bottom? I dont know what the anchored control is, but have you tried nesting ToolStripControlHosts? The one you have inside another one which hosts 2 things: the scroller and non scroller? – Ňɏssa Pøngjǣrdenlarp Jan 03 '15 at 14:21
  • @Plutonix Yes, I ended up doing something like that. – Christian Jan 03 '15 at 16:22

1 Answers1

3

My solution to this problem is to completely avoid using the normal menu control containment system and instead have the menu show one FlowLayoutPanel which instead contains my menu items.

This involved having to add some various trickeries to get the panel to behave nicely with the UI. The added advantage of this approach is more flexibility and control over the system.

On the downside, I noticed a degrade in performance when I have a tonne of sub-items, but I'll investigate this separately.

Christian
  • 27,509
  • 17
  • 111
  • 155