Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying ampersand in form label - C# [duplicate]

Tags:

c#

If I build a simple string like this:

string myStr = "Kayla & William";

And then simply set the label text on a form like this:

lbl_Phrase.Text = myStr;

The output in the form removes the ampersand (&)

enter image description here


I've tried:

  • escaping the &
  • ASCII encoding
  • char.ConvertFromUtf32(38)

When I debug and step through the code the string includes the & just fine. Also, I can write the string to Debug.WriteLine(myStr); and it looks great.

Is the problem related to how the form displays the string? How can I get the label to display the &?

like image 525
Automate This Avatar asked Mar 22 '23 09:03

Automate This


1 Answers

you need to escape it with use double ampersand && for displaying single ampersand &

Note : single & has different meaning that it will be treated as ACCESS KEY PREFIX character and you need to escape it with another &

Try This :

&&

OR

you can set UseMnemonic property of the label to false, and give only one ampersand & .when you set UseMnemonic to false ampersand will be treated as normal literal and displayed.

like image 154
Sudhakar Tillapudi Avatar answered Apr 26 '23 22:04

Sudhakar Tillapudi