试一试,不会什么“对不准”的。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, 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;
Down : Boolean;
FtPt,CurPt : TPoint;
implementation
{$R *.DFM}
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Down := TRUE;
FtPt := Point(X,Y);
CurPt := Point(X,Y);
Canvas.Pen.Mode := pmNotXor;
Canvas.Brush.Style := bsClear;
Canvas.Rectangle(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;
Canvas.Rectangle(FtPt.X,FtPt.Y,CurPt.X,CurPt.Y);
CurPt := Point(X,Y);
Canvas.Rectangle(FtPt.X,FtPt.Y,CurPt.X,CurPt.Y);
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Down := FALSE;
Canvas.Rectangle(FtPt.X,FtPt.Y,CurPt.X,CurPt.Y);
end;
end.