参见英文答案 >
Enter “&” symbol into a text Label in Windows Forms?5个
考虑:
考虑:
Label label = new Label(); label.Text = "&";
但是……在我运行程序之后,我看不到& ;,
我想只显示角色. &安培;
解决方法
那是因为&在标签,按钮和菜单中添加前缀以访问关键字符,即可以使用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&&,正如其他几个答案所提到的那样.