程序如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
Currenti,iWidth,iHeight,M,N : Integer;
procedure panelClick(Sender: TObject);
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.panelClick(Sender: TObject);
begin
if Currenti=TPanel(Sender).Tag then
begin
TPanel(Sender).Width:=iWidth;
TPanel(Sender).Height:=iHeight;
TPanel(Sender).Top:=(Currenti div N)*iHeight;
TPanel(Sender).Left:=(Currenti mod N)*iwidth;
Exit;
end;
Currenti:=TPanel(Sender).Tag;
TPanel(Sender).Width:=352;
TPanel(Sender).Height:=288;
TPanel(Sender).Top:=0;
TPanel(Sender).Left:=0;
TPanel(Sender).BringToFront;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
PanelW : array[0..63] of TPanel;
i,k,x,chanelnum : Integer;//5*4
s,temp:string;
begin
chanelnum:=24;//通道数
if chanelnum <= 4 then
x:=4
else
if chanelnum<9 then
x:=9
else
if chanelnum<=16 then
x:=16
else
if chanelnum <= 25 then
x:=25
else
if chanelnum<=36 then
x:=36
else
if chanelnum<=49 then
x:=49
else
if chanelnum<=64 then
x:=8;
Str(Sqrt(x):5:0, Temp);
S :=temp;
k:=strtoint(s);
M:=k;
N:=k;
iWidth:=352 div n;
iHeight:=288 div m;
for i := 0 to M*N-1do
begin
PanelW:=TPanel.Create(self);
PanelW.Parent:=Self;//self为父级控件
PanelW.Width:=iWidth;
PanelW.Height:=iHeight;
PanelW.Visible:=True;
PanelW.Top:=(i div N)*iHeight;
PanelW.Left:=(i mod N)*iwidth;
PanelW.Caption:=inttostr(i);
PanelW.OnDblClick:=panelClick;
PanelW.Tag:=i;
end;
end;
end.