Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 325
Spectraljump Avatar asked Dec 01 '10 14:12

Spectraljump


People also ask

Apa yang dimaksud dengan komputer rakitan?

Komputer rakitan adalah sebuah komputer dimana komponen-komponen terpisah digabungkan (dirakit) menjadi kesatuan utuh yang dibuat oleh pribadi, baik oleh teknisi maupun kita sendiri. Dengan adanya komputer rakitan ini, pengguna dapat leluasa memodifikasi komponen dalam komputer.


2 Answers

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"; 
like image 172
BoltClock Avatar answered Oct 19 '22 23:10

BoltClock


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

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

like image 37
Jens Avatar answered Oct 20 '22 01:10

Jens