Type "&" in a text label in Windows Forms?

How to enter special characters in Label in C # (Windows Forms)?

If you try to write "&" in the shortcut, you get something like an underscore instead.

So what is equivalent to C # "&"? ("\ &" obviously does not work).

+78
c # special-characters winforms label
Dec 01 '10 at 14:01
source share
5 answers

Two ways:

  • Escape with another ampersand ( && ).

  • Set UseMnemonic for this label to false . This makes all ampersands in the text be taken literally, so you do not need to double them. However, you lose the underline and key access features.

    You can set the value either in the constructor or in the code:

     myLabel.UseMnemonic = false; myLabel.Text = "Text&Text"; 
+163
Dec 01 2018-10-01
source share

Add another ampersand in front of it, therefore: &&

Or take a look at the following: Label.UseMnemonic (MSDN documentation)

+15
Dec 01 2018-10-01
source share

You can go out and, adding twice, try && .

+7
Dec 01 2018-10-01
source share

I donโ€™t know how to use '&' in the designer, but in the code you can use '& &' to show one '&'

-2
Dec 01 2018-10-01
source share

Try the following:

 ((char)0x26).ToString() 
-four
Feb 08 '13 at 15:13
source share



All Articles