如何使用“&” C# 按钮文本属性中的字符才能正确显示

发布于 2024-09-27 00:03:45 字数 389 浏览 1 评论 0原文

我的 C# 代码是:

        Button button;
        button = new Button();

        button.Text = "B&C";

        this.Controls.Add(button);

但是当我运行此代码时,表单上的按钮显示 BC(并且 C 通常带有下划线)。

我知道我可以将其设置为 B&&C 以使我的按钮文本显示为 B&C,但我的应用程序的用户在配置按钮上的文本时不会知道输入 B&&C。

他们只需输入 B&C 或 C&B 等,就会显示为 BC 和 CB。

我该如何解决这个问题?

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

脱离于你 2024-10-04 00:03:45

只需替换“&”即可在设置按钮文本之前:

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

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

button.Text = text.Replace("&","&&");
早乙女 2024-10-04 00:03:45

您可以简单地使用;

button.Text = "B && C";

You can use simply;

button.Text = "B && C";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文