Twodordan Twodordan - 1 year ago 111
C# Question

Enter "&" symbol into a text Label in Windows Forms?

How would one enter special characters into a

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).

Answer Source

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";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download