unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormPaint(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
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;
currect:TRect;
Capturing:Bool=false;
dx,dy:integer;
implementation
{$R *.dfm}
procedure TForm1.FormPaint(Sender: TObject);
begin
form1.Canvas.Brush.Style:=bsclear; // 空心矩形框
form1.Canvas.Rectangle(currect);
end;
procedure TForm1.FormMouseMove(Sender:TObject;Shift:TShiftState;X,Y:Integer);
var
pt:TPoint;
begin
pt.X:=X;
pt.Y:=Y;
if PtInRect(currect,pt) then
begin
screen.Cursor:=crHandPoint;
end
else
begin
screen.Cursor:=crDefault;
end;
if (Capturing) and PtInRect(currect, pt) then
begin
currect:=Rect(x-dx,
y-dy,
x-dx+(currect.Right-currect.Left),
y-dy+(currect.Bottom-currect.Top));
form1.Refresh;
end;
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Capturing:=true;
dx:=X-currect.Left;
dy:=Y-currect.Top;
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Capturing:=false;
end;
initialization
currect:=Rect(0, 0, 100, 100);
end.
delphi 可移动矩形框
最新推荐文章于 2021-09-03 11:31:26 发布