View Single Post
  #4  
Old 10-28-2003, 09:37 AM
nikolayj nikolayj is offline
Senior Member
 
Join Date: May 2002
Posts: 335
Default RE: how can i Draw a Line on canvas?

Hi how about this:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
nCurrX, nCurrY, nPointX, nPointY: Integer;

implementation

{$R *.dfm}

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
nCurrX := X;
nCurrY := Y;
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then
with Canvas do begin
MoveTo(nPointX, nPointY);
LineTo(nCurrX, nCurrY);
end;

end;

procedure TForm1.FormClick(Sender: TObject);
begin
nPointX := nCurrX;
nPointY := nCurrY;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
nPointX := 300;
nPointY := 300;
end;

end.

Click Accept if Helped
Reply With Quote