Reputation: 959
I am using latest Delphi 10.1 and creating a multi-device app. I have a TLayout
that has Align
set to top
. I have a TLabel
that is with in the mentioned TLayout
and has Align
set to Client
and its TLabel.AutoSize
set to True
.
Problem is that when I have long label text, TLabel
grows but TLayout
doesn't grow.
How can I fix this?
Upvotes: 1
Views: 1649
Reputation: 76607
You know the new size of the label as soon as you change its text.
Label.Width
will update to reflect the resized width.
You have 3 options.
Everytime you change the text of the label, also read its width
and update the associated TLayout to match (not recommended).
Assign the OnResize
event of the label and do something like this (recommended):
procedure TForm45.Label1Resize(Sender: TObject); const ExtraWidthOfLayout = 10; var Lbl: TLabel; Layout: TLayout; begin if (Sender is TLabel) and (TLabel(Sender).Parent is TLayout) then begin Lbl:= TLabel(Sender); Layout:= TLayOut(Lbl.Parent); Layout.Width:= Lbl.Width + ExtraWidthOfLayout; end; end;
Note that you can use the same event for all labels.
TLabel.DoResize
.Upvotes: 1