Label属性接受C#转义序列 [英] Label property to accept escape sequences in C#

查看:192
本文介绍了Label属性接受C#转义序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/4325094/enter-symbol-into-a-text-label-in-windows-forms">Enter &ldquo;&安培;&rdquo;的符号到Windows窗体的文本标签?

有没有属性的标签来显示'和;在C#?

Is there any property for a label to display '&' in C#?

我想在标签中显示的客户名称。当有任何'和;'在名称符号,它越来越显示为_。例如, A和B XXX 是越来越显示为 AB B 强调。

I'm trying to display customer names in a label. When there is any '&' symbol in the name, it's getting displayed as '_'. For example, A&B XXX is getting displayed as AB with B underlined.

而不是硬编码的,有没有什么办法来显示&安培; 符号接收通过设置任何财产的手段

Instead of hardcoding, is there any way to display & symbols as received by means of setting any property?

推荐答案

标签控制不能显示由转义序列的控制字符EN codeD和有没有财产,控制这一点。原因是它使用内置的框架,它不扩大控制字符的标准图形程序提请其文本。且不说对像 \ t 的含义是模糊的?有多少空间应该被视为一个标签

The Label control can't display the control characters encoded by escape sequences, and there's no property that controls that. The reason is it draws its text using standard graphics routines built into the framework, which do not expand control characters. Not to mention that the meaning of something like \t is ambiguous: how many spaces should be treated as a tab?

如果你想显示的东西就像一个标签或跳过到一个新行,则需要到c很难$ C $进入你的字符串:

If you want to display something like a tab or skip to a new line, you'll need to hardcode it into your string:

myTabLabel.Text = "This is a spaced          out label!";
myNewLineLabel.Text = "First line" + Environment.NewLine + "Second line"


编辑回应编辑的问题:

在默认情况下,连字符(&安培; )字符表示的关键助记符的标签。这被示为带下划线的字母和有益的键盘访问。每当用户presses被指定为助记符随着<大骨节病>替代键特定的控制键,该控件接收输入的焦点。 (当然,在一个标签,这是不能获得焦点的情况下,Tab键顺序的下一个控件接收焦点,它是一个标签preceding一个文本框或其他控件本身不支持键盘有用助记符。)

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 标签控件属性假。:当此属性为false ,符号字符不是PTED作为访问键preFIX字符间$ P $,但作为代替文字字符。

That's all fine and good, of course, but sometimes you don't need a mnemonic sequence assigned to a particular control, or as in your case, you want the ampersand to be displayed rather than consumed as a mere mnemonic indicator. You can easily achieve this by setting the UseMnemonic property of the Label control to "False." When this property is false, the ampersand character is not interpreted as an access key prefix character, but instead as a literal character.

另外,如果你不想要这个属性无论出于何种原因设置或要继续使用的不同的的字符作为键盘助记符,你可以插入的两个的&符旁边,对方在你的标签标题。这将基本上是逃跑的符号字符,使其显示为文字,而是用下面的其他符号的快捷键preFIX字符的字符。

Alternatively, if you don't want to set this property for whatever reason or you want to continue using a different character as the keyboard mnemonic, you can insert two ampersand characters next to each other in your label caption. This will essentially "escape" the ampersand character so that it is displayed as a literal, but use the character following the other ampersand as the access key prefix character.

那么,是这样的:

myLabel.Text = "Milk && &Cookies"

会产生:牛奶和放大器;曲奇(与C中的曲奇下划线)与 UseMnemonic ==真

这篇关于Label属性接受C#转义序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆