Interesting concept. Here is an alternative to caching percentages for each control. You can use TControl.ReadBounds to get the original bounds of the control.
Usage:
procedure TForm1.FormResize(Sender: TObject);
begin
WinControlProportionalResizer(Self);
end;
procedure WinControlProportionalResizer(const AParent: TWinControl);
var
LReadBounds, LParentReadBounds: TRect;
LIndex, LReadWidth, LReadHeight, LParentReadWidth, LParentReadHeight: Integer;
LControl: TControl;
begin
for LIndex := 0 to AParent.ControlCount - 1 do begin
LControl := AParent.Controls[LIndex];
if LControl.Align = alNone then begin
LReadBounds := LControl.ReadBounds;
LReadWidth := LReadBounds.Right - LReadBounds.Left;
LReadHeight := LReadBounds.Bottom - LReadBounds.Top;
LParentReadBounds := AParent.ReadBounds;
LParentReadWidth := LParentReadBounds.Right - LParentReadBounds.Left;
LParentReadHeight := LParentReadBounds.Bottom - LParentReadBounds.Top;
LControl.SetBounds(LReadBounds.Left * AParent.Width div LParentReadWidth,
LReadBounds.Top * AParent.Height div LParentReadHeight,
LReadWidth * AParent.Width div LParentReadWidth,
LReadHeight * AParent.Height div LParentReadHeight);
if LControl is TCustomButton then begin
LControl.Font.Height := LControl.Height - 2;
end;
end;
end;
end;
Note: I'm not sure I coded the same font sizing, but, anyway, see what you think.