2

我正在尝试模仿这个答案,但尽管这有效:

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

这不会:

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);
    }
}

为什么?

我这样称呼他们:

contextMenuStrip1.Items.Add(new TrackBarMenuItem());
contextMenuStrip1.Items.Add(new PanelMenuItem());
4

1 回答 1

7

设置面板的最小尺寸:

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;
  }
}
于 2012-04-18T13:05:13.443 回答