How to create an immutable context menu item?

I have a simple context menu. And I would like to add to it a title element that cannot be selected, not even highlighted by the mouse cursor. When I set Enabled = false; , I can still mark it, and it seems stupid because it is clearly disabled and the text is gray.


Example:

Like it. I cannot mark or select the menu item. It should never be blue. So I want this in my C # application. Simple, without styles.

Vw5gS.jpg


Test code:
 public Form1() { ContextMenuStrip = new ContextMenuStrip(); ContextMenuStrip.Font = new Font("Arial", 8); ToolStripItem a = ContextMenuStrip.Items.Add("--- Title ---"); a.Enabled = false; a.Font = new Font("Consolas", 16, FontStyle.Bold | FontStyle.Italic); ContextMenuStrip.Items.Add("Alice"); ContextMenuStrip.Items.Add("Bob"); ContextMenuStrip.Items.Add("Conrad"); } 
+3
source share
1 answer

I think you want to add a ToolStripLabel element to your strip, for example:

 ContextMenuStrip.Items.Insert(0, new ToolStripLabel("--- Title ---")); 

This should add a label that serves as a marker, and should not show anything when the mouse moves over it.

(Here's a similar answer here , which covers the same point.)

+5
source

All Articles