Try this
Interface
type
TForm1 = class(TForm)
procedure MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
Dragging:boolean; //Are we dragging?
DragX,DragY:integer; //What are the current mouse co-ords in the drag?
CtlX,CtlY:integer; //Original posn of Control
StartPt:TPoint;
DragCtl:TControl; //What is being dragged?
end;
Implementation
procedure TForm1.MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var ix,iy:integer;
pt:TPoint;
begin
//We're going to drag this...
DragCtl:=TControl(Sender);
Dragging:=true;
screen.Cursor:=crNone;
DragCtl.BringToFront;
StartPt:=Point(X,Y);
//How far off centre is the cursor to start with?
ix:=(DragCtl.Width shr 1)-X;
iy:=(DragCtl.Height shr 1)-Y;
//These are only for reference, and are relative..
DragX:=X+ix;
DragY:=Y+iy;
//Centre the cursor in the image
GetCursorPos(pt);
SetCursorPos(pt.X+ix,pt.Y+iy);
end;
procedure TForm1.MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
//Finished Dragging...
DragCtl:=nil;
Dragging:=false;
Screen.Cursor:=crDefault;
end;
procedure TForm1.MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var dx,dy:integer;
begin
if Dragging then
begin
dx:=X-DragX;
dy:=Y-DragY;
DragCtl.SetBounds(DragCtl.Left+dx,DragCtl.Top+dy,DragCtl.Width,DragCtl.Height);
end;
end;
This is taken from a Delphi app I have, so there might be some things that are windows specific [Like Get/SetCursorPos],
but you can probably get away without them (if it's a problem, you can lose the centring code as well);
You can wire up the Mouse events to any control, including the form.
If there are problems let me know, and we can work through it. I haven't tested it on a lazdev box as yet, but it works fine in all versions of Delphi.
HTH
DSP