Fmx İçin Örnek ScroolBox İçinde Paneller;
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts, FMX.StdCtrls, FMX.Controls.Presentation;
type
TPanelParameter = record
Parent : TComponent;
PanelAdet : Integer;
PanelWidth : Integer;
PanelHeight : Integer;
LayoutMargin : Array of Integer;//Left,Right,Top,Bottom
PanelMargin : Array of Integer;//Left,Right,Top,Bottom
end;
type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
ScrollBox1: TScrollBox;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
procedure PanelCreate(Parameter : TPanelParameter);
end;
var
Form1: TForm1;
implementation
uses Math;
{$R *.fmx}
procedure TForm1.Button1Click(Sender: TObject);
var
xParams : TPanelParameter;
begin
with xParams do
begin
Parent := self;
PanelAdet := 10;
PanelWidth := 90;
PanelHeight := 100;
LayoutMargin := [0,0,5,0];
PanelMargin := [5,0,0,0];
end;
PanelCreate(xParams);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
xParams : TPanelParameter;
begin
width := 150;
with xParams do
begin
Parent := self;
PanelAdet := 10;
PanelWidth := 100;
PanelHeight := 100;
LayoutMargin := [0,0,5,5];
PanelMargin := [5,0,0,0];
end;
PanelCreate(xParams);
end;
procedure TForm1.PanelCreate(Parameter : TPanelParameter);
var
WrapperScroolBox : TScrollBox;
PanelsLayout : Array Of TLayout;
Panels : Array Of TPanel;
i,j : Integer;
LayoutAdet : Integer;
LayoutPanelAdet : Integer;
PanelCounter : Integer;
begin
If Assigned(Parameter.Parent.FindComponent('WrapperScroolBox')) then TScrollBox(Parameter.Parent.FindComponent('WrapperScroolBox')).Free;
WrapperScroolBox := TScrollBox.Create(Parameter.Parent);
WrapperScroolBox.Name := 'WrapperScroolBox';
WrapperScroolBox.Parent := TControl(Parameter.Parent);
WrapperScroolBox.Align := TAlignLayout.Client;
LayoutPanelAdet := Trunc(WrapperScroolBox.Width / (Parameter.PanelWidth+Parameter.PanelMargin[0]+Parameter.PanelMargin[1]));
LayoutAdet := Ceil(Parameter.PanelAdet/LayoutPanelAdet);
PanelCounter := 0;
SetLength(PanelsLayout,LayoutAdet);
SetLength(Panels,Parameter.PanelAdet);
for I := 0 to Pred(LayoutAdet) do
begin
PanelsLayout[i] := TLayout.Create(WrapperScroolBox);
PanelsLayout[i].Parent := WrapperScroolBox;
PanelsLayout[i].Name := 'PanelsLayout' + IntToStr(i);
PanelsLayout[i].Align := TAlignLayout.Top;
PanelsLayout[i].Height := Parameter.PanelHeight;
PanelsLayout[i].Margins.Left := Parameter.LayoutMargin[0];
PanelsLayout[i].Margins.Right := Parameter.LayoutMargin[1];
PanelsLayout[i].Margins.Top := Parameter.LayoutMargin[2];
PanelsLayout[i].Margins.Bottom := Parameter.LayoutMargin[3];
for j := 0 to Pred(LayoutPanelAdet) do
begin
if PanelCounter < Parameter.PanelAdet then
begin
Panels[PanelCounter] := TPanel.Create(PanelsLayout[i]);
Panels[PanelCounter].Align := TAlignLayout.Right;
Panels[PanelCounter].Width := Parameter.PanelWidth-(Parameter.PanelMargin[0]+Parameter.PanelMargin[1]);
Panels[PanelCounter].Margins.Left := Parameter.PanelMargin[0];
Panels[PanelCounter].Margins.Right := Parameter.PanelMargin[1];
Panels[PanelCounter].Margins.Top := Parameter.PanelMargin[2];
Panels[PanelCounter].Margins.Bottom := Parameter.PanelMargin[3];
Panels[PanelCounter].Parent := PanelsLayout[i];
Panels[PanelCounter].Name := 'Panels' + IntToStr(PanelCounter);
end;
PanelCounter := Succ(PanelCounter);
end;
for j := Pred(PanelsLayout[i].ComponentCount) downto 0 do
begin
If PanelsLayout[i].Components[j] is TPanel then TPanel(PanelsLayout[i].Components[j]).Align := TAlignLayout.Left;
end;
end;
end;
end.