Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Creating a label at runtime and getting it to wrap
Tue, Aug 25 2020 5:42 AMPermanent Link

Paul Coshott

Avatar

Hi All,

I am creating a number of controls at run-time to display some search results. One of the labels could have very little text in it or it could have a lot. I want the label to set it's height automatically and to wrap so it's all displayed.

The attachment shows what happens when I set AutoSize.Height = False and Height = 44. The code below produces a label (the yellow one) that shows only the first line of text with a height of 16..

Anyone know how to do this?

The label is being created with the following code:

   with TLabel.Create(bp_desc) do begin
     Name := 'labCompat' + IntToStr(iComp);
     Caption := strCompatability;
     Font.Size := 12;
     Format.Wrap := True;
     AutoSize.Height := True;
     Layout.Position := lpTopLeft;
     Layout.Stretch := lsRight;
     Layout.Consumption := lcBottom;
     Margins.Bottom := 0;
     Margins.Left := 3;
     Margins.Right := 3;
     Margins.Top := 3;
     Background.Fill.Color := clYellow;
     Font.Color := clElevateDarkGray;
     Padding.Left := 10;
     Tag := iProductId;
   end;

Cheers,
Paul



Attachments: label_wrap.jpg
Tue, Aug 25 2020 9:13 AMPermanent Link

Matthew Jones

Paul Coshott wrote:

>       Layout.Stretch := lsRight;

That stands out to me. But there are two options that conflict with each other - I can't remember which. Create a test label in the IDE and fiddle with the options until you get what you need.

--

Matthew Jones
Tue, Aug 25 2020 5:46 PMPermanent Link

Paul Coshott

Avatar

"Matthew Jones" wrote:

>> Create a test label in the IDE and fiddle with the options until you get what you need.

Thanks Matthew. I played around with it, and all I needed to do was add AutoSize.Width := False;

That did it!

Thanks again.

Cheers,
Paul
Image