不可点击的上下文菜单标题

Dar*_*ung 8 c# contextmenu winforms

创建上下文菜单时,有没有办法包含标题文本?例如,当用户单击按钮时,我希望上下文菜单显示两个选项.选项上方还应有文字,例如:"请选择一个选项".

这可能吗?

Han*_*ant 16

您无法与设计师一起完成,但您可以在代码中执行此操作:

public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
        contextMenuStrip1.Items.Insert(0, new ToolStripLabel("Please select an option"));
        contextMenuStrip1.Items.Insert(1, new ToolStripSeparator());
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 您可能也喜欢将文本加粗:`contextMenuStrip1.Items.Insert(0, new ToolStripLabel("Please select an option") { Font = new Font(DefaultFont, FontStyle.Bold) });` (2认同)