Multiline property for Labels?

Tex8503

Active Member
Licensed User
Longtime User
Hey folks,
I know there's no multiline property for labels - but for the hell of it - I tried it and it worked in the IDE on the PC. However, when I go to compile for the device it says 'Dbasic.EnhancedControls.CEhancedLabel' does not contain a definition for 'multiline'

Is there a reason that labels can't use the multiline property other than its just not part for B4P ? Is it not supported on the devices or was this just an oversight? Is there an alternate way to do this using door?
 

Discorez

Member
Licensed User
Longtime User
Such variant than isn't pleasant?
B4X:
Label.Text = "First line" & CRLF & "Second line"
e.t.c...
 

Tex8503

Active Member
Licensed User
Longtime User
Believe me... if it were that simple - I'd have done it already

I'm loading dynamic text into a certain area... So I don't exactly know where the line breaks need to be to get it to fit into the area. I could change the label to a textbox and disable it - but that seems like a bit more of an ugly fix...
 

mjcoon

Well-Known Member
Licensed User
This code should work:
B4X:
Label1.Text = "first" & CRLF & "second"

Tex8503 has already explained why that is no use to him.

But is there a function that, given a text string, a font/size, and a width in pixels, will deliver the same string but with the necssary line breaks added? That would satisfy the requirement.

Mike.
 

mjcoon

Well-Known Member
Licensed User
I see. You are looking for Wrap support. Labels do not support it. You may want to check Image.StringWidth. It will not be simple, but it is still possible to measure substrings of the text and decide where to add CRLF.

That might form a useful utility module.

Don't fall into the trap I set for myself a few years ago (before I retired). I wrote just such a word-wrap routine. But it did not occur to me that sometimes the text to wrap would have a "word" too wide for the display area. (Actually someone had written "####....####" as a paragraph separator.) Because I had, too cleverly for my own good, written a recursive function, it recursed infinitely trying to find where to insert the CRLF and after a long pause, crashed the poor clerk's workstation.

Mike.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…