Non-clickable Context Menu Header

五迷三道 提交于 2020-01-03 08:36:30

问题


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


来源:https://stackoverflow.com/questions/4595116/non-clickable-context-menu-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!