Location of mouse on an object

Posted on 2003-02-18
Medium Priority
Last Modified: 2010-04-04
I need to return the current location of the mouse when I perform an onclick (from the panel/lable etc). Any ideas?

Question by:Morgans43
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3

Author Comment

ID: 7979248
.. additional.... the location needs to be relative to the object rather than the screen as a whole... ie I need to know WHERE on the OBJECT I clicked.. not WHERE on the SCREEN...

Expert Comment

ID: 7979359

Why don't you implement a OnMouseUp() event, this returns the X, Y position of the mouse when you let the mouse up.

declare a private variable to the form called FMousePoint of type TPoint.

in the form create, initialize the x and y values to 0

in your OnMouseUp event handler

FMousePoint.X := X;
FMousePoint.Y := Y;

in your OnClick() utilize the FMousePoint values.

that seems to work, but perhaps I misunderstood your needs, if so, please explain in more detail.

hope this helps,

Author Comment

ID: 7979397
Was under the impression that this will give the location of the mouse on the screen rather than on the object.. will try it though.

Accepted Solution

Codeslave earned 150 total points
ID: 7979402
Another option is to make use of the global Mouse object. It records the current mouse position in screen coordinates. In order to convert to local coordinates, simply use the ScreenToClient method that is introduced in TControl.

For example,


procedure TMyComponent.DoSomething;
  lLocal: TPoint;
  lLocal := ScreenToClient(Mouse.CursorPos);
  // lLocal now contains the mouse cursor position in
  // local component coordinates.

Author Comment

ID: 7979676
Thanks to both, but this was the one that really helped me...

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month9 days, 21 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question