gpt4 book ai didi

delphi - Delphi XE 中的 GridPanel 问题

转载 作者:行者123 更新时间:2023-12-02 04:19:13 25 4
gpt4 key购买 nike

GridPanel 有问题!难道我做错了什么?第一行第 2 列是调整表单大小时的错误。使用 Delphi XE 6 和 10.2.2 进行测试!将 TGridPanel 放置到表单中并将“Align”设置为“alClient”。启动表单并调整其大小。

尝试以下代码:

procedure TForm5.Button1Click(Sender: TObject);
var
Col,Row: Integer;
CI: TControlItem;
Panel: TPanel;
Rows, Cols: Integer;
begin
GridPanel1.RowCollection.BeginUpdate;
GridPanel1.ColumnCollection.BeginUpdate;
GridPanel1.ColumnCollection.BeginUpdate;

GridPanel1.RowCollection.Clear;
GridPanel1.ColumnCollection.Clear;

Rows := 6;
Cols := 4;

for Row := 1 to Rows do
begin
with GridPanel1.RowCollection.Add do
begin
SizeStyle := ssPercent;
Value := 100 / Rows;
end;
end;

for Col := 1 to Cols do
begin
with GridPanel1.ColumnCollection.Add do
begin
SizeStyle := ssPercent;
Value := 100 / Cols;
end;
end;

for Row := 0 to GridPanel1.RowCollection.Count - 1 do
begin
for Col := 0 to GridPanel1.ColumnCollection.Count - 1 do
begin
Panel := TPanel.Create(Self);
Panel.Parent := GridPanel1;
CI := GridPanel1.ControlCollection.Add;
CI.Column := Col;
CI.Row := Row;
Panel.Caption := 'Row ' + Row.ToString + ' Col ' + Col.ToString;
CI.Control := Panel;
end;
end;
GridPanel1.ColumnCollection.EndUpdate;
GridPanel1.RowCollection.EndUpdate;
GridPanel1.ColumnCollection.EndUpdate;
end;

最佳答案

正如 Tom Brunberg 所指出的,设置 Panel.Parent 将它们放入控件集合中并管理事物。

  for Row := 0 to GridPanel1.RowCollection.Count - 1 do
begin
for Col := 0 to GridPanel1.ColumnCollection.Count - 1 do
begin
Panel := TPanel.Create(Self);
Panel.Parent := GridPanel1;
Panel.Caption := 'Row ' + Row.ToString + ' Col ' + Col.ToString;
end;
end;

您的代码使集合最终有 48 个控件,而不是 24 个。

form1.Caption := 'ControlCollection.Count:' + IntToStr(GridPanel1.ControlCollection.Count);

关于delphi - Delphi XE 中的 GridPanel 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52762869/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com