Ver Mensaje Individual
  #10  
Antiguo 24-05-2012
Avatar de duilioisola
[duilioisola] duilioisola is offline
Miembro Premium
 
Registrado: ago 2007
Ubicación: Barcelona, España
Posts: 1.743
Reputación: 20
duilioisola Es un diamante en brutoduilioisola Es un diamante en brutoduilioisola Es un diamante en bruto
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
      { Private declarations }
   public
      { Public declarations }
   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);

   // Agrando el Form para que entren todos los Paneles
   Self.Width := maxc * 9 + 20;
   Self.Height := PNLMain.Height + maxl * 9 + 50;

   // Escondo el panel contenedor para acelerar el proceso
   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;
            // Algo para diferenciar un panel de otro
            Color := ((c + l) * $0F0F);
         end;
         LCantidad.Caption := IntToStr(maxl * c + l);
         inc(l);
      end;
      inc(c);

      // Solo refresco la pantalla por cada columna
      Application.ProcessMessages;
   end;

   // Muestro el panel contenedor
   PNLContenedor.Visible := True;
end;

procedure TForm1.BLiberarClick(Sender: TObject);
var
   i: integer;
begin
   // Escondo el panel contenedor para acelerar el proceso
   PNLContenedor.Visible := False;

   for i := PNLContenedor.ComponentCount - 1 downto 0 do
      if (PNLContenedor.Components[i] is TPanel) then
         TPanel(PNLContenedor.Components[i]).Free;

   // Muestro el panel contenedor
   PNLContenedor.Visible := True;
end;

procedure TForm1.EColumnasChange(Sender: TObject);
begin
   LCantidad.Caption := IntToStr(StrToIntDef(EColumnas.Text, 0) * StrToIntDef(ELineas.Text, 0));
end;

end.
Responder Con Cita