delphi - How do I get the absolute mouse co-ordinates when mouse is over a control -


i want absolute co-ordinates of mouse when mouse on control has been placed on host control. e.g. host control panel button placed on panel. want mouse co-ordinates relative panel when mouse on button.

i have tried obvious see get:

procedure tfmworkingscreen.pnlscreenareamousemove(sender: tobject;   shift: tshiftstate; x, y: integer); begin    statusbar1.simpletext := 'left ' + inttostr(x) + '  right ' + inttostr(y); end; 

clearly work when mouse on panel control. there way required co-ordinates?

add onmousemove event handler child control, button in example. in onmousemove event handler receive x , y cursor coordinates respect child control's client area. if host control immediate parent of control onmousemove event has fired use control's clienttoparent method:

var   posrelparent: tpoint: .... posrelparent := (sender tcontrol).clienttoparent(point(x, y)); 

if parent control may further parent/child relationship can pass parent control clienttoparent:

posrelparent := (sender tcontrol).clienttoparent(point(x, y), theparent); 

if wish express position relative arbitrary controls client area can converting via screen coordinates, global frame of reference.

var   posrelscreen, posrelothercontrol: tpoint:   othercontrol: twincontrol; .... posrelscreen := (sender tcontrol).clienttoscreen(point(x, y)); posrelothercontrol := othercontrol.screentoclient(posrelscreen); 

as 1 final offering, can use getmessagepos obtain screen relative coordinates of mouse last message retrieved call getmessage.

var   msgpos: tpoint; .... msgpos := tsmallpoint(getmessagepos()); 

at point can use somecontrol.screentoclient(msgpos) coordinates of cursor relative control's client area. makes sense call getmessagepos if in event handler triggered queued mouse message.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -