看看这个
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
bb: Boolean = False;
PX,PY,PX1,PY1: Integer;
implementation
{$R *.dfm}
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if bb = False then
begin
Form1.Canvas.Pen.Color := clred;
Form1.Canvas.Pen.Width := 1;
Form1.Canvas.Pen.Style := psSolid;
//Form1.Canvas.Pen.Mode := pmBlack;
PX := X;
PY := Y;
BB := True;
end;
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if bb = True then
begin
Form1.Canvas.Pen.Color := clBtnFace;
Form1.Canvas.MoveTo(PX,PY);
Form1.Canvas.lineto(PX1,PY1);
Form1.Canvas.Pen.Color := clred;
Form1.Canvas.MoveTo(PX,PY);
Form1.Canvas.LineTo(X,Y);
PX1:=X;
PY1:=Y;
end;
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
BB:= False;
form1.Update;
end;
end.