Unit uMovePNG;
Interface
Uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, PNGImage, ExtCtrls;
Type
TForm1 =
Class(TForm)
picPNG: TImage;
Procedure FormCreate (Sender: TObject);
Procedure picPNGMouseDown (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
Procedure picPNGMouseUp (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.picPNGMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
Begin
If Button = mbLeft
Then
Begin
PosX:= X;
PosY:= Y;
ShowCursor(False);
Ti.Enabled:= True;
End;
End;
Procedure TForm1.MoveTimer(Sender: TObject);
Var
P: TPoint;
Begin
P:= ScreenToClient(Mouse.CursorPos);
picPNG.Top:= P.Y - PosY;
picPNG.Left:= P.X - PosX;
End;
Procedure TForm1.picPNGMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
Begin
If Button = mbLeft
Then
Begin
Ti.Enabled:= False;
ShowCursor(True);
End;
End;
End.