Align, autosize and so on. Simple collision detection. lazarus / 31-LCL ---------------------------------------------------------------------- hakahl · 2013-12-12 09:21 Hi! I have a TPanel on which I (during runtime) place other TPanel children on. I want the top property of the Children to be fixed and the TPanels to be placed from left to right occupying as much space as possible without overlapping. The purpose is to display a booking table and I couldn't get the Visual Planit to work on my installation... Is this possible to achieve with autosize, align, anchor and so on? Thanks in advance! -H ---------------------------------------------------------------------- howardpc · 2013-12-12 10:50 If the Top of the child panels is 0, you can achieve this simply using the Align property of each child panel (set each to alLeft, the last one to alClient). If the form will be a fixed size, then the following code will set it up at runtime. If you want the form and child panels to be resizeable then more complex anchoring code would also be needed. Code: [Select]unit mainChildPanels; {$mode objfpc}{$H+} interface uses   SysUtils, Forms, Controls, Graphics, ExtCtrls, StdCtrls, Spin; type   { TForm1 }   TForm1 = class(TForm)     BCreateChildPanels: TButton;     EPanelCount: TSpinEdit;     LPanelCount: TLabel;     PBase: TPanel;     procedure BCreateChildPanelsClick(Sender: TObject);   private     procedure CreateChildPanels(aPanelCount: integer);   end; const   ChildPanelTop = 25;  // set this appropriately var   Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.BCreateChildPanelsClick(Sender: TObject); begin   CreateChildPanels(EPanelCount.Value); end; procedure TForm1.CreateChildPanels(aPanelCount: integer); var   ht, i, wid: integer;   procedure PlaceNewChildPanel(anIndex: integer);   var     pnl: TPanel;     lastWid: integer;   begin     pnl:=TPanel.Create(Self);     lastWid:=PBase.ClientWidth-(Pred(aPanelCount)*wid);     if (anIndex=aPanelCount-1) then       pnl.SetInitialBounds(anIndex*wid, ChildPanelTop, lastWid, ht)     else pnl.SetInitialBounds(anIndex*wid, ChildPanelTop, wid, ht);     pnl.BevelInner:=bvLowered;     pnl.Caption:=Format('child %d',[anIndex]);     if Odd(anIndex) then pnl.Color:=clMoneyGreen;     pnl.Parent:=PBase;   end; begin   ht:= PBase.ClientHeight-ChildPanelTop;   if (aPanelCount<=0) or (ht <=0) then Exit;   wid:= PBase.ClientWidth div aPanelCount;   for i:= 0 to Pred(aPanelCount) do     PlaceNewChildPanel(i); end; end.