How to break lines and format labels
Johan Lund posted in Developing in Bindows on November 10th, 2010
If you have ever needed to put a line break into the text of a BiLabel you have probably experienced that a simple \n character doesn’t work. In this post I will show you a couple of ways you can use to control the formatting of your labels.
First let’s examine the label.
You can either put the text into the text property:
or inside the tag:
In the last example, where the text is put into the tag, you can get a line break simply by pressing Enter in your code, like this:
So far, we have been using the ”text” property of the BiLabel to give it simple text, however, we can also enter fully formatted HTML code via the HTML property, like this:
Since I had to escape the < and > characters it looks a bit messy. Obviously, if you just called setHtml from JavaScript you wouldn’t have to escape those characters like that; However, since we are now in markup land, we have to do it. If the HTML code was slightly more complicated we would need an even better way to write our HTML.
The trick is to use namespace to have nicely formatted XHTML right inside the markup, that is inside the tag.
First, let’s declare the namespace in the application tag:
Then, we can use it like this:
The result of the above code would look like this:
Good luck and enjoy your formatting!
November 12th, 2010 at 1:37 am
is it the correct way to do
December 8th, 2010 at 2:25 am
A very useful new information.
Does it works in version 3.0?
December 10th, 2010 at 8:50 am
Yes it works in Bindows 3.0. It’s been in Bindows since 1.3 or something maybe even earlier.
October 1st, 2011 at 6:59 pm
Codebix.com - Your post is on Codebix.com…
This post has been featured on Codebix.com. The place to find latest articles on programming. Click on the url to reach your post’s page….