unit ZeichneU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TFarbe = TColor;
TZeichnePanel = class(TPanel)
protected
Licht: TShape;
fColor: TColor;
procedure setColor(c: TColor);
procedure myOnResize(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
procedure Paint; override;
published
property Farbe: TColor read fcolor write setcolor;
end; // of TZeichnePanel
procedure Register;
var
rot: TFarbe;
gruen: TFarbe;
blau: TFarbe;
gelb: TFarbe;
rosa: TFarbe;
tuerkis: TFarbe;
implementation
constructor TZeichnePanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Width := 30;
Height := 30;
Top := 100;
Left := 100;
setcolor(fcolor);
Licht := TShape.Create(Self); //Shape,Kreis
Licht.Parent := Self;
Licht.Width := 29;
Licht.Height := 29;
Licht.Shape := stCircle;
Licht.Top := 1;
Licht.Left := 1;
Licht.Brush.Color := fcolor;
OnResize := myOnResize;
end;
procedure TZeichnePanel.Paint;
begin
canvas.Brush.Color := clsilver;
canvas.Pen.color := clblack;
canvas.rectangle(0,0,50,50);
end;
procedure TZeichnePanel.setColor(c: TColor);
var
x:integer;
begin
if c = rot then fcolor := clred;
if c = gruen then fcolor := cllime;
if c = gelb then fcolor := clyellow;
if c = blau then fcolor := clblue;
if c = rosa then fcolor := clfuchsia;
if c = tuerkis then fcolor := clteal;
Licht := TShape.Create(Self); //Shape,Kreis
//Licht.Parent := Self;
Licht.Brush.Color := fcolor;
Randomize; //Zufall für Farben!!
x := random(6);
case x of
0: fcolor := clred;
1: fcolor := cllime;
2: fcolor := clblue;
3: fcolor := clyellow;
4: fcolor := clfuchsia;
5: fcolor := clteal;
end;
end;
procedure TZeichnePanel.myOnResize(Sender: TObject);
begin
paint;
end;
Procedure Register;
begin
RegisterComponents('Standard',[TZeichnePanel]);
end;
end.
Ehrlich gesagt peil ich schon teilweise selber net ganz durch.
Steht teilweise absoluter schwachsinn drin.....