我试图模仿this回答,但这有效:
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());
答案 0 :(得分:6)
设置面板的最小尺寸:
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;
}
}