views:

49

answers:

1

Hello,

My C# code is:

        Button button;
        button = new Button();

        button.Text = "B&C";

        this.Controls.Add(button);

But when I run this code the button on my form displays BC (and the C is usually underlined).

I know that I can set it to B&&C to get my button text to come out as B&C but the users of my app will not know to type B&&C when they configure the text on their buttons.

They will just type B&C, or C&B, etc, which will come out as BC and CB.

How can I work around this?

Thanks.

+5  A: 

Simply replace the "&" before setting the button text:

button.Text = text.Replace("&","&&");
Philippe Leybaert
Henk Holterman