* * *

Author Topic: GetCursorPos  (Read 545 times)

Middlecope

  • New member
  • *
  • Posts: 9
GetCursorPos
« on: February 10, 2012, 02:33:33 am »
On a form I have a Paintbox.
On the Canvas of the Paintbox I draw an Ellipse(x1,y1,x2,y2)
If I click inside the ellipse in the PaintboxOnClick I state GetCursorPos(p).
Unfortunately the  p.X and p.Y are outside the ranges [x1..x2] and [y1..y2]
Does anyone has an idea what I do wrong?
Thanks for your attention
Teunis

Leledumbo

  • Hero Member
  • *****
  • Posts: 2989
Re: GetCursorPos
« Reply #1 on: February 10, 2012, 03:12:02 am »
AFAIK GetCursorPos returns cursor's global position (i.e. relative to the screen, not your application nor the specific control). Try calling ScreenToClient method from the specific control (TPaintBox in your case).

User137

  • Hero Member
  • *****
  • Posts: 503
Re: GetCursorPos
« Reply #2 on: February 10, 2012, 03:18:27 pm »
Alternatively you can declare variables mouseX, mouseY, and update their values in PaintBoxOnMouseMove event, by X, Y parameters.

Or even easier by using onMouseDown (or onMouseUp) event instead of onClick. You have those cursor coordinates passed as X, Y there too.
« Last Edit: February 10, 2012, 03:21:23 pm by User137 »

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads