.net - Label property to accept escape sequences in C# -


possible duplicate:
enter “&” symbol text label in windows forms?

is there property label display '&' in c#?

i'm trying display customer names in label. when there '&' symbol in name, it's getting displayed '_'. example, a&b xxx getting displayed ab b underlined.

instead of hardcoding, there way display & symbols received means of setting property?

the label control can't display control characters encoded escape sequences, , there's no property controls that. reason draws text using standard graphics routines built framework, not expand control characters. not mention meaning of \t ambiguous: how many spaces should treated tab?

if want display tab or skip new line, you'll need hardcode string:

mytablabel.text = "this spaced          out label!"; mynewlinelabel.text = "first line" + environment.newline + "second line" 

edit in response edited question:

by default, ampersand (&) character indicates key mnemonic label. shown underlined letter , useful keyboard access. whenever user presses key specified mnemonic particular control along alt key, control receives input focus. (of course, in case of label, can't receive focus, next control in tab order receives focus, useful label preceding textbox or other control not support keyboard mnemonics.)

that's fine , good, of course, don't need mnemonic sequence assigned particular control, or in case, want ampersand displayed rather consumed mere mnemonic indicator. you can achieve setting usemnemonic property of label control "false." when property false, ampersand character not interpreted access key prefix character, instead literal character.

alternatively, if don't want set property whatever reason or want continue using different character keyboard mnemonic, can insert two ampersand characters next each other in label caption. "escape" ampersand character displayed literal, use character following other ampersand access key prefix character.

so, like:

mylabel.text = "milk && &cookies" 

would produce: "milk & cookies" (with c in "cookies" underlined) usemnemonic == true.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -