In a Delphi 10.4.2 Win32 VCL Application on Windows 10, I use a TPanel
with AutoSize = True
.
The documentation says:
When AutoSize is True, the control resizes automatically when its contents change.
However, this is not the case when the size of its contents changes at run-time in this particular situation:
Place these controls on a VCL Application form:
object Button1: TButton
Left = 40
Top = 56
Width = 81
Height = 25
Caption = 'Button1'
TabOrder = 2
OnClick = Button1Click
end
object Panel1: TPanel
Left = 40
Top = 104
Width = 161
Height = 19
AutoSize = True
TabOrder = 1
object CheckBox1: TCheckBox
Left = 1
Top = 1
Width = 159
Height = 17
Align = alTop
Caption = 'bla bla bla bla bla bla'
TabOrder = 0
WordWrap = True
end
end
Then, in the Button's OnClick
handler, place this code:
procedure TForm1.Button1Click(Sender: TObject);
begin
Panel1.AutoSize := False;
try
Panel1.Width := Panel1.Width - 10;
finally
Panel1.AutoSize := True; // trying to refresh the Panel's height
end;
end;
This decreases the width of the Panel by 10 pixels each time.
However, the Panel's Height is not automatically resized!
How can I manually resize the Panel, so it reflects the changed Height of the Checkbox?