2

I'm trying to emulate this answer but though this works:

public class TrackBarMenuItem : ToolStripControlHost
{
    TrackBar trackBar;
    public TrackBarMenuItem()
        : base(new TrackBar())
    {
        trackBar = Control as TrackBar;
    }
}

This doesn't:

public class PanelMenuItem : ToolStripControlHost
{
    Panel panel;
    public PanelMenuItem()
        : base(new Panel())
    {
        panel = Control as Panel;
        Visible = true;
        Enabled = true;
        panel.AutoSize = false;
        panel.Size = new Size(100, 50);
    }
}

Why?

I'm calling them like this:

contextMenuStrip1.Items.Add(new TrackBarMenuItem());
contextMenuStrip1.Items.Add(new PanelMenuItem());
Community
  • 1
  • 1
ispiro
  • 26,556
  • 38
  • 136
  • 291

1 Answers1

7

Set the minimum size of the Panel:

public class PanelMenuItem : ToolStripControlHost {
  Panel panel;
  public PanelMenuItem()
    : base(new Panel()) {
    panel = Control as Panel;
    Visible = true;
    Enabled = true;
    panel.AutoSize = false;
    panel.Size = new Size(100, 50);

    panel.MinimumSize = panel.Size;
  }
}
LarsTech
  • 80,625
  • 14
  • 153
  • 225
  • Thanks. (So does that mean that context menu's always use the minimum size?) – ispiro Apr 18 '12 at 13:11
  • @ispiro It's the `ToolStripControlHost` that has issues with size of the control that it hosts. On some controls like Panel, it needs to have the `MinimumSize` set in order for it to be viewable. – LarsTech Apr 18 '12 at 13:15