Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop items in a ContextMenuStrip from treating ampersands specially?

I have a ContextMenuStrip which displays items which can be named by the user; the user is allowed to give the items names containing ampersands. When the ContextMenuStrip is shown, the items' treat the ampersands as escape sequences, and underline the next character.

I could double up all the ampersands before I set the items' Text members, but that member is used elsewhere in the code so if possible, I'd like to stop the ContextMenuStrip from treating ampersands specially. Is there a way to turn that behaviour off?

like image 817
Simon Avatar asked Dec 17 '22 07:12

Simon


1 Answers

use && to display a single &

Edit: Sorry, I missed the second part of your question :(

You could always use string.Replace("&", "&&") on the text when you set it, but that seems messy.

Another alternative would be to inherit from ToolStripMenuItem and override the Set of the Text Property to replace & with &&. That would be a little better as it would keep the code in once place.

like image 69
Pondidum Avatar answered Jan 11 '23 23:01

Pondidum