为什么这个 ToolStripControlHost 不起作用?



我试图模拟这个答案,但尽管这有效:

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

设置面板的最小大小:

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

相关内容

  • 没有找到相关文章

最新更新