Hi Martin, This works fine. Thanks so much. I got confused with the in built drag function. I was hoping that begindrag function should take care of it with outlining during drag etc which ofcourse is not happening now. Also is it possible to drag it to another container such as a panel? I will investigate that by and by. Thanks-a-lot for your help again.
Regards TFE, http://totallyfreeenergy.zxq.net --- In [email protected], "Martin Wynne" <gro...@...> wrote: > > Hi TFE, > > Here you go, use the OnMouseDown and OnMouseMove events for the TImage or > whatever: > > (can no doubt be much improved, dredged up from some old code, not checked) > ------------------- > > var > control_mousedown_X,control_mousedown_Y:integer; > > //_______________________________________________ > > procedure my_form.my_controlMouseDown(Sender: TObject; Button: TMouseButton; > Shift: TShiftState; X, Y: Integer); > > var > mousedown_p,control_p:TPoint; > > begin > if GetCursorPos(mousedown_p)=False then begin mousedown_p.X:=0; > mousedown_p.Y:=0; end; // mouse position in screen co-ords. > > control_p.X:= my_control.Left; > control_p.Y:= my_control.Top; > > control_mousedown_X:=mousedown_p.X-(my_form.ClientToScreen(control_p)).X; > // mouse offset within the control > control_mousedown_Y:=mousedown_p.Y-(my_form.ClientToScreen(control_p)).Y; > > end; > //_______________________________________________ > > procedure Tmy_form.my_controlMouseMove(Sender: TObject; Shift: TShiftState; > X, Y: Integer); > > var > mps:TPoint; > > begin > if Shift=[ssLeft] // mouse down, dragging? > then begin > if GetCursorPos(mps)=False then begin mps.X:=0; mps.Y:=0; end; > > with my_control do begin > Left:=(my_form.ScreenToClient(mps)).X-control_mousedown_X; > Top:=(my_form.ScreenToClient(mps)).Y-control_mousedown_Y; > end;//with > > end; > end; > //______________________________________________ > > regards, > > Martin. >

