unit draw;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
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
p1,p2:TPoint;
public
{ Public declarations }
end;
var
Form1: TForm1;
lastx,lasty:integer;
implementation
{$R *.DFM}
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
P1.x:=x;
P1.y:=y;
p2:=p1;
canvas.pen.Mode:=pmNot;
canvas.pen.Color:=clblack;
canvas.brush.Style:=bsclear;
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if (shift=[ssleft]) then begin
canvas.Rectangle(p1.x,p1.y,p2.x,p2.y); //擦除
canvas.Rectangle(p1.x,p1.y,x,y); //重画
p2.x:=x;
p2.y:=y;
end;
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
canvas.Rectangle(p1.x,p1.y,p2.x,p2.y); //擦除}
end;
end.