rppig
rppig

Reputation: 468

Why when I use a string "&&", it only shows "&" on the form label?

str = "&&";            
label1.Text = str;

but it only shows "&".

How do I fix it?

Upvotes: 0

Views: 176

Answers (2)

Mongus Pong
Mongus Pong

Reputation: 11477

The & means that the character after the & becomes the shortcut key. When that form has the focus pressing Alt+Shortcut Key will shift the focus to that control.

For a label, it shifts the focus to the control that is in the tab order following the label.

This means you can't just use the & character in the label as it has that special meaning. So to allow you to use the & in the label Windows lets you use &&. So setting the label text to be && will set the label of the text to be &.

Upvotes: 1

user195488
user195488

Reputation:

It is because the & (ampersand) is known as a mnemonic and it is being interpreted as such. Double-ampersand (&&) comes out as "Text & Text" when you do "Text && Text".

You can set the Label.UseMnemonic property to false. The default is true.

Upvotes: 9

Related Questions