The Label
control 无法显示由转义序列编码的控制字符,并且没有属性可以控制它。原因是它使用框架内置的标准图形例程绘制文本,该例程不会扩展控制字符。更不用说类似的意思了\t
不明确:应将多少个空格视为制表符?
如果您想显示选项卡之类的内容或跳到新行,则需要将其硬编码到字符串中:
myTabLabel.Text = "This is a spaced out label!";
myNewLineLabel.Text = "First line" + Environment.NewLine + "Second line"
编辑回应已编辑的问题:
By default, the ampersand (&
) character indicates the key mnemonic for a label. This is shown as an underlined letter and useful for keyboard access. Whenever the user presses the key that is specified as the mnemonic for a particular control along with the Alt key, that control receives the input focus. (Of course, in the case of a label, which can't receive focus, the next control in the tab order receives the focus, which is useful for a label preceding a textbox or other control that does not itself support keyboard mnemonics.)
当然,这一切都很好,但有时您不需要分配给特定控件的助记符序列,或者在您的情况下,您希望与号是显示的而不是仅仅作为助记符来使用。您可以通过设置轻松实现此目的UseMnemonic财产 http://msdn.microsoft.com/en-us/library/system.windows.forms.label.usemnemonic.aspx of the Label
控制为“False”。当此属性为 false 时,& 字符不会解释为访问键前缀字符,而是解释为文字字符。
或者,如果您出于某种原因不想设置此属性或者您想继续使用不同的字符作为键盘助记符,可以插入two标签标题中彼此相邻的 & 符号。这实际上会“转义”&符号,以便将其显示为文字,但使用另一个&符号后面的字符作为访问键前缀字符。
所以,像这样:
myLabel.Text = "Milk && &Cookies"
会产生:“Milk & Cookies”(“Cookies”中的 C 带有下划线)UseMnemonic == true
.