Visual Studio Express 2013中有特殊菜单项。
点击Panel
后看起来似乎已MenuItem
打开。例如:
如何为连接到MenuStrip
的{{1}}创建“面板菜单项”?它只是标准MenuItem
和标准隐藏MenuItem
,具有基于Panel
边框的动态排名?或者它是一个修改后的Form
来包含Graphics和Uri?
我搜索了类似的内容,但我找不到如何在MenuItem
内创建Panel,我不知道是否应该使用菜单创建普通ToolStrip
,或者某处的解决方案(自定义组件)。
答案 0 :(得分:1)
假设WinForms,您可以使用ToolStripControlHost来保存Panel或UserControl:
弹出窗口中显示的控件:
var panel = new Panel() {
BackColor = Color.White,
MinimumSize = new Size(150, 72),
Size = MinimumSize,
};
panel.Paint += (s, e) => {
TextRenderer.DrawText(e.Graphics, "Pop-up Panel",
SystemFonts.DefaultFont, panel.ClientRectangle,
Color.Black, Color.Empty,
TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
};
ToolStrip控件显示面板:
var hostTool = new ToolStripControlHost(panel) {
Padding = Padding.Empty,
Margin = Padding.Empty
};
var downButton = new ToolStripDropDownButton("Panel Menu") {
Alignment = ToolStripItemAlignment.Right,
DisplayStyle = ToolStripItemDisplayStyle.Text,
DropDownDirection = ToolStripDropDownDirection.BelowLeft,
};
((ToolStripDropDownMenu)downButton.DropDown).ShowCheckMargin = false;
((ToolStripDropDownMenu)downButton.DropDown).ShowImageMargin = false;
downButton.DropDown.AutoSize = false;
downButton.DropDown.Size = new Size(panel.Width + 12, panel.Height + 4);
downButton.DropDown.Items.Add(hostTool);
var tool = new ToolStrip();
tool.Items.Add(downButton);
this.Controls.Add(tool);
结果: