Kod: Tümünü seç
unit line;
interface
uses
Windows, Messages, Graphics, SysUtils, Classes, Controls;
type
TLine = class(TGraphicControl)
private
{ Private declarations }
FLineData: word;
function GetLineWidth: Integer;
function GetLineColour: TColor;
function GetLineData: word;
procedure SetLineWidth(const NewWidth: Integer);
procedure SetLineColour(const NewColour: TColor);
procedure SetLineData(const NewData: Word);
protected
{ Protected declarations }
procedure Paint; override;
public
{ Public declarations }
published
{ Published declarations }
property Data : word read FlineData write SetLineData;
property LineColour : TColor read GetLineColour write SetLineColour;
property LineWidth : Integer read GetLineWidth write SetLineWidth;
property OnClick;
property OnMouseDown;
property OnMouseUp;
end;
procedure Register;
implementation
function TLine.GetLineWidth: Integer;
begin
Result := Canvas.Pen.Width;
end;
function TLine.GetLineColour: TColor;
begin
Result := Canvas.Pen.Color;
end;
function TLine.GetLineData: word;
begin
Result := FLineData;
end;
procedure TLine.SetLineData(const NewData: Word);
begin
if NewData <> FLineData then
begin
FLineData := NewData;
Invalidate; // redraws the component
end;
end;
procedure TLine.SetLineWidth(const NewWidth: Integer);
begin
if NewWidth <> Canvas.Pen.Width then
begin
Canvas.Pen.Width := NewWidth;
Invalidate; // redraws the component
end;
end;
procedure TLine.SetLineColour(const NewColour: TColor);
begin
if NewColour <> Canvas.Pen.Color then
begin
Canvas.Pen.Color := NewColour;
Invalidate;
end;
end;
procedure TLine.Paint;
begin
inherited;
// buraya mousedown ve mouseup kodlarını eklemem lazım
Canvas.Moveto(x1,y1);
Canvas.Lineto(x2,y2);
end;