unit Jong;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, stdctrls;
type
TForm1 =
class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
TStein =
class(TGraphicControl)
private
{ Private-Deklarationen }
x,y: Integer;
Color: TColor;
Pressed: Boolean;
protected
{ Protected-Deklarationen }
procedure Paint;
override;
procedure MouseDown
(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
override;
public
{ Public-Deklarationen }
constructor Create(AOwner: TComponent);
override;
property Caption;
end;
var
Form1: TForm1;
test: TStein;
implementation
{$R *.DFM}
constructor TStein.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Color := clBtnFace;
Canvas.Brush.Color := Color;
Pressed := false;
Caption := '
Test';
SetBounds (0,0,50,50);
end;
procedure TStein.MouseDown (Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
inherited MouseDown (Button, Shift, X, Y);
if Button = mbLeft
then
begin
Pressed := true;
Paint;
end;
end;
procedure TStein.Paint;
begin
x := (Width - Canvas.TextWidth(Caption))
div 2;
y := (Height- Canvas.TextHeight(Caption))
div 2;
Canvas.Rectangle (3, 3, Width-3, Height-3);
canvas.TextOut(x,y, Caption);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
test := TStein.Create(self);
end;
end.