Unit uMoveForm;
Interface
Uses
Windows, SysUtils, Classes, Controls, ExtCtrls, Forms;
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 MoveTimer (Sender: TObject);
End;
VAR
Form1: TForm1;
Ti: TTimer;
PosX: Integer;
PosY: Integer;
Implementation
{$R *.dfm}
Procedure TForm1.FormCreate(Sender: TObject);
Begin
DoubleBuffered:= True;
Ti:= TTimer.Create(Application);
Ti.Interval:= 30;
Ti.Enabled:= False;
Ti.OnTimer:= Form1.MoveTimer;
End;
Procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
Begin
If Button = mbLeft
Then
Begin
PosX:= Mouse.CursorPos.X - Left;
PosY:= Mouse.CursorPos.Y - Top;
ShowCursor(False);
Ti.Enabled:= True;
End;
End;
Procedure TForm1.MoveTimer(Sender: TObject);
Begin
Top:= Mouse.CursorPos.Y - PosY;
Left:= Mouse.CursorPos.X - PosX;
End;
Procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
Begin
If Button = mbLeft
Then
Begin
Ti.Enabled:= False;
ShowCursor(True);
End;
End;
End.