Mirror

Check if a Point(x, y) is under the mouse cursor (Views: 100)


Problem/Question/Abstract:

How to check if a Point(x, y) is under the mouse cursor

Answer:

You define a small rectangle around the mouse cursor and scan the points - in the MouseMove event:

{ ... }
var
  aRect: TRect;
begin
  aRect := rect(x - 5, y - 5, x + 5, y + 5);
  {Then scan your points:}
  for i := 0 to high(PointArray) do
    if PtInRect(aRect, PointArray[i]) then
    begin
      x := PointArray[i].x;
      y := PointArray[i].y;
      break;
    end;
end;

<< Back to main page