The "&" in a label

pisceswzh

Well-known member
Joined
Mar 19, 2007
Messages
96
Programming Experience
1-3
Hi,

I met a problem with the label tool. It should be easy to answer.

When I set label.text = "Ernst & Young", the label will display the text as "Ernst _Young". Is there a way to avoid the label to interpret the "&" into "underscore the next character"?

Thanks!
 
That's great!

But what if the data is pulled from a database and I don't know if there is an "&" in it? Does that means I have to replace "&" to "&&" whenever I try to assign a value to label.text?
 
Hi,

I met a problem with the label tool. It should be easy to answer.

When I set label.text = "Ernst & Young", the label will display the text as "Ernst _Young". Is there a way to avoid the label to interpret the "&" into "underscore the next character"?

Thanks!

By the way, that "underscore" is for keyboard shortcuts. A label cant have the focus, but focus will go to the next focusable component in the tab order

["&Ernst && Young" LABEL] [TEXTBOX]

Pressing Alt+E will focus the textbox
 
That's great!

But what if the data is pulled from a database and I don't know if there is an "&" in it? Does that means I have to replace "&" to "&&" whenever I try to assign a value to label.text?

One way of doing it, is when you pull the data out of the database, when you assign the data to the label's text property simply add this:
VB.NET:
.Replace("&", "&&")

'The full line would be something like:
YourLabel.Text = TheDataString.Replace("&", "&&")
 
One way of doing it, is when you pull the data out of the database, when you assign the data to the label's text property simply add this:
VB.NET:
.Replace("&", "&&")

'The full line would be something like:
YourLabel.Text = TheDataString.Replace("&", "&&")

If the label is bound, you dont have anything to do with the process of putting the text into the label, and you'd be better off doing the replacement in the SELECT query itself. Typically, database values arent bound to labels; they are bound to read only borderless text boxes, as this still allows the info to be copied. There is no requirement to manipulate the & in text box text
 
Back
Top