Hier mal was ganz einfaches um zu verstehen, wie man sich selbst sowas macht... hehe
Delphi-Quellcode:
unit FormLine;
interface
uses
SysUtils, Classes, Controls, Windows, Graphics;
type
TFormLine =
class(TCustomControl)
private
FStartPosX : Integer;
FStartPosY : Integer;
FEndPosX : Integer;
FEndPosY : Integer;
FPenColor : TColor;
procedure SetStartPosX(
const Value: Integer);
procedure SetStartPosY(
const Value: Integer);
procedure SetEndPosX(
const Value: Integer);
procedure SetEndPosY(
const Value: Integer);
procedure SetPenColor(
const Value: TColor);
procedure Paint;
override;
protected
{ Protected-Deklarationen }
public
{ Public-Deklarationen }
published
property StartPosX: Integer
read FStartPosX
write SetStartPosX;
property StartPosY: Integer
read FStartPosY
write SetStartPosY;
property EndPosX : Integer
read FEndPosX
write SetEndPosX;
property EndPosY : Integer
read FEndPosY
write SetEndPosY;
property Color;
property PenColor : TColor
read FPenColor
write SetPenColor;
{ Published-Deklarationen }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('
Beispiele', [TFormLine]);
end;
procedure TFormLine.SetStartPosX(
const Value: Integer);
begin
IF (Value <> FStartPosX)
THEN BEGIN
FStartPosX := Value;
Invalidate;
END;
end;
procedure TFormLine.SetStartPosY(
const Value: Integer);
begin
IF (Value <> FStartPosY)
THEN BEGIN
FStartPosY := Value;
Invalidate;
END;
end;
procedure TFormLine.SetEndPosX(
const Value: Integer);
begin
IF (Value <> FEndPosX)
THEN BEGIN
FEndPosX := Value;
Invalidate;
END;
end;
procedure TFormLine.SetEndPosY(
const Value: Integer);
begin
IF (Value <> FEndPosY)
THEN BEGIN
FEndPosY := Value;
Invalidate;
END;
end;
procedure TFormLine.SetPenColor(
const Value: TColor);
begin
IF Value <> FPenColor
THEN BEGIn
FPenColor := Value;
invalidate;
END;
end;
procedure TFormLine.Paint;
begin
Canvas.Brush.Color := Color;
Canvas.FillRect(Canvas.ClipRect);
Canvas.Pen.Color := FPenColor;
Canvas.MoveTo(FStartPosX, FStartPosY);
Canvas.LineTo(FEndPosX, FEndPosY);
end;
end.