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?
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"
EDIT in response to edited question:
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.)
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.
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.
So, something like:
myLabel.Text = "Milk && &Cookies"
would produce: "Milk & Cookies" (with the C in "Cookies" underlined) with UseMnemonic == true
.