c# – 为什么不显示在Windows窗体标签中?

参见英文答案 > Enter “&” symbol into a text Label in Windows Forms?5个
考虑:
Label label = new Label();

label.Text = "&";

但是……在我运行程序之后,我看不到&amp ;,

如何在标签中显示该字符?

我想只显示角色. &安培;

解决方法

那是因为&在标签,按钮和菜单中添加前缀以访问关键字符,即可以使用Alt按下这些字符以直接为控件提供焦点.
label1.UseMnemonic = false;

将摆脱这种行为.

UseMnemonic的文档:

true if the label doesn’t display the ampersand character and underlines the character after the ampersand in its displayed text and treats the underlined character as an access key; otherwise,false if the ampersand character is displayed in the text of the control. The default is true.

如果你需要显示&和访问键的行为,那么你需要逃避& as&&,正如其他几个答案所提到的那样.

相关文章

文章浏览阅读6.2k次,点赞2次,收藏3次。C#数学运算表达式解...
文章浏览阅读5.2k次,点赞6次,收藏7次。程序要做到用户配置...
文章浏览阅读9k次。错误信息检测到 ContextSwitchDeadlock M...
文章浏览阅读2w次,点赞10次,收藏9次。我发生错误时的环境:...
文章浏览阅读9.8k次。C# 二进制字节流查找函数IndexOf ...
文章浏览阅读2.5w次,点赞3次,收藏9次。c#DataGridView数据...