Link to home
Start Free TrialLog in
Avatar of skel
skel

asked on

Inserting various lines in a Static Text Control

How can I, for a short example, add 2 texts on different lines in a Static Text control? I've tried Text1 + Chr(13) + Chr(10) + Text2, but it didn't work. Other characters, such as Chr(9), are interpreted correctly, but Chr(13) is not.

Thanks in advance
Jaime
Avatar of 333
333

What you mean with Static Text control? If it's TLabel, then make sure the AutoSize property is set to true. I've tried this and it works:

Label1.Caption:='Text1'+#13#10+'Text2'
ASKER CERTIFIED SOLUTION
Avatar of viktornet
viktornet
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of skel

ASKER

Thanks.. but I have a problem... I need to set AutoSize to true, but when, for example, I place 2 lines of text, only first line appears completely, and also a part of the second line is shown. I have this in a for loop :

Text.Caption := Text.Caption + Address + #9 + Code;
Text.Caption := Text.Caption + #9#9 + Mnemonic + #13#10;

And as I told you, only the first line and part of the second line are displayed. This always happen, even if I try to display more than 2 lines.  What can I do?

Thanks in advance
Jaime

P.S. If I set AutoSize to false, I am not able to add more lines than the size of the control. This StaticText control is placed over a Panel in order to can scroll the text using a vertical scroll bar.
If you set the AutoSize to true and know exactly how many lines there are going to be then use this method....
StaticText.Caption := StaticText.Caption + #10#13+StaticText.Caption;
StaticText.Height := NumberOfTexLines * 16;
//if your caption has two lines of text then the height will be 32...2 lines * 16 = 32