以前我回答过的,再发一遍吧。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
procedure Draw(X1,Y1,X2,Y2 : integer);
end;
var
Form1: TForm1;
Down : Boolean;
FtPt,CurPt : TPoint;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
Down := FALSE;
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Down := TRUE;
Canvas.Pen.Mode := pmNotXor;
FtPt := Point(X,Y);
CurPt := Point(X,Y);
Draw(FtPt.X,FtPt.Y,CurPt.x,CurPt.Y);
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Down := FALSE;
// Draw(FtPt.X,FtPt.Y,CurPt.x,CurPt.Y);
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if not Down then Exit;
Draw(FtPt.X,FtPt.Y,CurPt.x,CurPt.Y);
CurPt := Point(X,Y);
Draw(FtPt.X,FtPt.Y,CurPt.x,CurPt.Y);
end;
procedure TForm1.Draw(X1,Y1,X2,Y2 : integer);
begin
Canvas.MoveTo(X1,Y1);
Canvas.LineTo(X2,Y2);
end;
end.