unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TForm1 =
class(TForm)
procedure FormCreate(Sender: TObject);
procedure OnPanelClick(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
const
nPanels = 9;
var
Form1: TForm1;
FPanels:
array[0..nPanels-1]
of TPanel;
implementation
{$R *.DFM}
//******************************************************************************
procedure TForm1.FormCreate(Sender: TObject);
const
PanelsPerRow = 3;
PanelsPerCol = 3;
var
i, j: Cardinal;
Top, Left, Height, Width: Cardinal;
begin
Top:= 0;
Left:= 0;
Height:= Self.ClientHeight
div PanelsPerCol;
Width:= Self.ClientWidth
div PanelsPerRow;
for i := 0
to PanelsPerCol-1
do
begin
for j := 0
to PanelsPerRow - 1
do
begin
FPanels[i]:= TPanel.Create(Self);
//Formular ist Owner
//hier das Control, das den Panel enthält (hier auch das Formular)
FPanels[i].Parent:= Self;
FPanels[i].OnClick:= OnPanelClick;
FPanels[i].Top:= Top;
FPanels[i].Left:= Left;
FPanels[i].Height:= Height;
FPanels[i].Width:= Width;
FPanels[i].Color:= clBlue;
Left:= Left + Width;
end;
Top:= Top + Height;
Left:= 0;
end;
end;
procedure TForm1.OnPanelClick(Sender: TObject);
begin
//Farbe invertieren
TPanel(Sender).Color:= TPanel(Sender).Color
xor clWhite;
end;
end.