Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread How to implementing a Flow Layout?
Fri, Jan 12 2018 3:10 PMPermanent Link

Mario Enríquez

Open Consult

Hi folks,

I need to dynamically add child panels inside a master panel, once the right edge its reached, the next child should start another row starting at the left edge.

It appears I'm almost there, but couldn't figure out how to start a new row. Been playing around with Reset property of the Layout but haven't found a solution yet.

Here's a snippet of the code:

procedure TForm1.btnAgregarClick(Sender: TObject);
var
  pnEtapa : TPanel;
begin
  pnEtapa := TPanel.Create(pnlBoard);
  pnEtapa.Background.Fill.Color := clRed;
  pnEtapa.Width := 250;
  pnEtapa.Height := 250;       
  pnEtapa.Margins.Bottom := 10;
  pnEtapa.Margins.Left := 10;
  pnEtapa.Margins.Right := 10;
  pnEtapa.Margins.Top := 10;
  pnEtapa.LayoutOrder := FEtapaCount;
  pnEtapa.Layout.Position := lpLeft;
  pnEtapa.Layout.Consumption := lcRight;

  if FRowCount = 2 then
  begin
     pnEtapa.Layout.Reset := True;
     FRowCount := 0;
  end
  else
  begin
     pnEtapa.Layout.Reset := False;
     Inc(FRowCount);
  end;

  Inc(FEtapaCount);
end;

procedure TForm1.Form1Show(Sender: TObject);
begin
  FRowCount := 0;
  FEtapaCount := 2;
end;

Any advice?

Regards,
Mario
Fri, Jan 12 2018 4:41 PMPermanent Link

Uli Becker

Mario,

> It appears I'm almost there, but couldn't figure out how to start a new row. Been playing around with Reset property of the Layout but haven't found a solution yet.

Let EWB do this job for you Smile

What you want is the Layout.Overflow property:

procedure TForm1.btnAgregarClick(Sender: TObject);
var
   pnEtapa : TPanel;
begin
   pnEtapa := TPanel.Create(BasicPanel1);
   pnEtapa.Background.Fill.Color := clRed;
   pnEtapa.Width := 250;
   pnEtapa.Height := 250;
   pnEtapa.Margins.Bottom := 10;
   pnEtapa.Margins.Left := 10;
   pnEtapa.Margins.Right := 10;
   pnEtapa.Margins.Top := 10;
   pnEtapa.Layout.Position := lpTopLeft;
   pnEtapa.Layout.Consumption := lcRight;
   pnEtapa.Layout.Overflow := loBottom;    <--------------
end;

Uli
Fri, Jan 12 2018 5:11 PMPermanent Link

Mario Enríquez

Open Consult

Thank you very much Uli, that did the trick!

Regards,
Mario
Image