Non-clickable Context Menu Header

2019-06-17 01:52发布

问题:

When creating a context menu, is there a way to have header text included? For example, when a user clicks a button, I want a context menu to show with two options. There should also be text above the options, with a sentence such as: 'Please select an option'.

Is this possible?

回答1:

You can't do it with the designer but you can do it in code:

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


回答2:

You can make a menu with 4 elements in this order:

  • "Please select an option" -Disabled (this make it gray out and unlickable)
  • Separator (------)
  • Option1 -Enabled
  • Option2 -Enabled