tl, dr: This is a bug in TFlowPanel .
Usually, AutoSize and Align properties combine very well by default, as this is taken care of already at the TControl level, so I wondered why this happened. I noticed the override TFlowPanel method in AlignControls and decided to bypass it for testing purposes:
type TWinControlAccess = class(TWinControl); TAlignControls = procedure(Instance: TObject; AControl: TControl; var Rect: TRect); TFlowPanel = class(Vcl.ExtCtrls.TFlowPanel) protected procedure AlignControls(AControl: TControl; var Rect: TRect); override; end; TForm1 = class(TForm) ... procedure TFlowPanel.AlignControls(AControl: TControl; var Rect: TRect); begin // Skip TCustomFlowPanel.AlignControls TAlignControls(@TWinControlAccess.AlignControls)(Self, AControl, Rect); end; procedure TForm1.FlowPanel1Resize(Sender: TObject); begin // Do my own aligning of the last button if FlowPanel1.ClientWidth < Button5.BoundsRect.Right then begin Button5.Left := 1; Button5.Top := Button1.Height + 1; end else if FlowPanel1.ClientWidth > Button4.BoundsRect.Right + Button5.Width then begin Button5.Left := Button4.BoundsRect.Right; Button5.Top := 1; end; end;
Now it works as expected. So what happened to the TFlowPanel implementation of AlignControls ? It looks like this:
if AutoSize then Rect := TRect.Create( Rect.Left, Rect.Top, Rect.Left + (ExplicitWidth - (Width - (Rect.Right - Rect.Left))), Rect.Top + (ExplicitHeight - (Height - (Rect.Bottom - Rect.Top))));
When this part is commented out, the behavior is the same as with Align , and also not. Now I would like to introduce this to the CC, but perhaps I do not notice some of its aspects. Please edit or comment on when (and then why) this code is really necessary.
source share