开发者

How to use an "&" character in a C# button text property to display properly

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.

开发者_如何学CHow can I work around this?

Thanks.


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

button.Text = text.Replace("&","&&");


You can use simply;

button.Text = "B && C";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜