113

How would one enter special characters into a Label in C# (Windows Forms)?

If you try to write a "&" into a label you'll get a sort of underscore instead..

So what's the C# equivalent of "&"? ("\&" obviously doesn't work).

0

5 Answers 5

228

Two ways:

  • Escape it with another ampersand (&&).

  • Set UseMnemonic for that label to false. This causes all ampersands within the text to be taken literally so you don't need to double any of them. You'll lose the underlining and access key features though.

    You can set the value either in the designer, or in code:

    myLabel.UseMnemonic = false;
    myLabel.Text = "Text&Text";
    
6
20

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

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

0
9

You can escape & by adding it two times, to try &&.

0

I don't know how to use '&' in the designer, but in the code you can use '&&' for showing one '&'

1
  • 5
    "&&" works fine in the designer. Just input it where you change the Text. Dec 1, 2010 at 14:10
-4

Try this:

((char)0x26).ToString()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.