Why doesnโ€™t appear and appear in the Windows Forms shortcut?

Consider:

Label label = new Label(); label.Text = "&"; 

But ... I can not see & after starting the program.

Code

How to show this symbol in the label?

I want to show only the symbol. & Amp;

+6
source share
3 answers

This is because & in shortcuts, buttons, and menus has a prefix for accessing key characters, that is, those characters that you can press with Alt to directly focus on the control.

 label1.UseMnemonic = false; 

get rid of this behavior.

From the UseMnemonic documentation:

true if the label does not display the ampersand character and underscores the character after the ampersand in its displayed text and processes the underlined character as an access key; otherwise false if the ampersand character is displayed in the control text. The default is true .

If you need to display & and passkey behavior, you need to escape & like && , as mentioned by several other answers.

+15
source

Use this:

 private void Form1_Load(object sender, EventArgs e) { label1.Text = "&&"; } 
+5
source

& used as a localized resource in Windows Forms. And it is also used to indicate shortcuts. Therefore, you need to avoid this:

 this.label1.Text = "&&"; 
+4
source

Source: https://habr.com/ru/post/906458/


All Articles