吴兄弟,以前有个托动图片的,你假如有用就拿去看:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, AppEvnts, jpeg, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
ApplicationEvents1: TApplicationEvents;
procedure Image1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
procedure Image1MouseUp(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
procedure ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
x,y,nx,ny,ox,ol,ot,oy:integer;
p:tpoint;
d:boolean;
implementation
{$R *.dfm}
procedure TForm1.Image1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
d:=true;
getcursorpos(p);
ox:=p.x;
oy:=p.y;
ol:=image1.left;
ot:=image1.Top;
end;
procedure TForm1.Image1MouseUp(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
d:=false;
end;
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
if d then
begin
getcursorpos(p);
x:=p.x-ox;
y:=p.y-oy;
image1.left:=ol+x;
image1.top:=ot+y;
end;
end;
end.