答案 0 :(得分:1)
我在VertScrollBox组件中使用TGridLayout做了类似的项目......
步骤......
添加项目的程序......
var
pnl : TPanel;
begin
pnl := TPanel.Create(self);
pnl.text := 'hi there!';
// here you should create and add images to panel. make sure the parent of each object is the pnl object.
pnl.parent := GridLayout1;
end;
调整大小时,添加时以及删除项目时都会调用以下代码。
procedure TfrmMain.adjustViews;
var
itemsPerRows: double;
rows: double;
begin
// for grid on vertical scroll
if GridLayout1.ControlsCount > 0 then begin
itemsPerRows := trunc(GridLayout1.Width / GridLayout1.ItemHeight);
rows := GridLayout1.ControlsCount / itemsPerRows;
GridLayout1.height := rows * GridLayout1.ItemWidth;
end;
// for grid on horizontal scroll
if GridLayout2.ControlsCount > 0 then
GridLayout2.Width := GridLayout2.ControlsCount * GridLayout2.ItemWidth;
end;
备注:
希望它有所帮助!