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());
有帮助吗?

解决方案

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;
  }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top