Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Mouse position on the form?

Posted on 1999-07-19
3
Medium Priority
?
189 Views
Last Modified: 2010-04-06
How can I get the mouse position on the form? I know I can use OnMouseMove-event and then store those values into some global variables, but is there a better way? I have tried
Mouse.CursorPos, but that doesn't work. It seems to give me the position on the screen and not on the form.
0
Comment
Question by:tonitop
[X]
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
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
Epsylon earned 200 total points
ID: 1389699
procedure TForm1.FormClick(Sender: TObject);
var p: TPoint;
begin
  p := mouse.CursorPos;
  p := Form1.ScreenToClient(p);
  Label1.Caption := IntToStr(p.x);
  Label2.Caption := IntToStr(p.y);
end;

0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1389700
That should work   :o)

Cheers,

Epsylon.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1389701
hi all,

additional possibilities


//move as mentioned
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  StatusBar1.SimpleText := intToStr(x)+':'+inttostr(y);
end;

//Win-Api
procedure TForm1.FormClick(Sender: TObject);
var P : TPoint;
begin
  GetCursorPos(P);
  P.x := P.x-ClientOrigin.x;
  P.y := p.y-ClientOrigin.y;
  StatusBar1.SimpleText := intToStr(p.x)+':'+inttostr(p.y);
end;


meikl ;-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

715 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