He limpiado la prueba que hice y te la envío para que puedas hacer tus pruebas.
Con 2000 paneles tarda unos 3 segundos.
Con 5000 paneles tarda unos 8 segundos.
Código Delphi
[-]
unit UPruebaPanel;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
PNLMain: TPanel;
PNLContenedor: TPanel;
BCrear: TButton;
BLiberar: TButton;
EColumnas: TEdit;
ELineas: TEdit;
LCantidad: TLabel;
procedure EColumnasChange(Sender: TObject);
procedure BCrearClick(Sender: TObject);
procedure BLiberarClick(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BCrearClick(Sender: TObject);
var
c, l: integer;
maxc, maxl: integer;
p: TPanel;
begin
maxc := StrToIntDef(EColumnas.Text, 0);
maxl := StrToIntDef(ELineas.Text, 0);
Self.Width := maxc * 9 + 20;
Self.Height := PNLMain.Height + maxl * 9 + 50;
PNLContenedor.Visible := False;
c := 0;
while (c < maxc) do
begin
l := 0;
while (l < maxl) do
begin
p := TPanel.Create(PNLContenedor);
with p do
begin
Name := Format('Panel_%d_%d', [c, l]);
Parent := PNLContenedor;
BevelInner := bvNone;
BevelOuter := bvNone;
Caption := '';
Top := l * 9;
Left := c * 9;
Height := 9;
Width := 9;
Color := ((c + l) * $0F0F);
end;
LCantidad.Caption := IntToStr(maxl * c + l);
inc(l);
end;
inc(c);
Application.ProcessMessages;
end;
PNLContenedor.Visible := True;
end;
procedure TForm1.BLiberarClick(Sender: TObject);
var
i: integer;
begin
PNLContenedor.Visible := False;
for i := PNLContenedor.ComponentCount - 1 downto 0 do
if (PNLContenedor.Components[i] is TPanel) then
TPanel(PNLContenedor.Components[i]).Free;
PNLContenedor.Visible := True;
end;
procedure TForm1.EColumnasChange(Sender: TObject);
begin
LCantidad.Caption := IntToStr(StrToIntDef(EColumnas.Text, 0) * StrToIntDef(ELineas.Text, 0));
end;
end.