Solved

How to get x and y coordinates of cursor..

Posted on 2004-08-18
3
213 Views
Last Modified: 2010-05-02
In a module, I have:

Type PointApi
  x As Long
  y As Long
End Type

Declare Function GetCursorPos Lib "user32" (IpPoint As PointApi) As Long
‘’’’’’’’’’’’’’
In a cmdButton_Click, I have

Private Button1_Click()
Dim p As PointApi
Dim xp As Long
Dim yp As Long
xp = GetCursorPos(p)
yp = GetCursorPos(p)
MsgBox xp & ", " & yp          ‘<---  no matter where I click, I get 1, 1

End Sub

Also, I would like to get the Button1.Top and Button1.Left as well.  Thank you in advance for your input.

Mike
0
Comment
Question by:Mike Eghtebas
3 Comments
 
LVL 19

Accepted Solution

by:
Shauli earned 300 total points
ID: 11837185
I dont know what you want to acheive with the command button, however, using the MouseDown event you can get the precise location of the mouse using the integrated X and Y variables:

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'where X and Y are the mouse location
'do your stuff
End Sub


S
0
 

Assisted Solution

by:Imbue
Imbue earned 200 total points
ID: 11837191
Try using this code in the command button.


Dim p As PointApi

Call GetCursorPos(p)
MsgBox p.x & ", " & p.y
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 11837451
Shauli,
Thank you very much for good directions I have been receiving from you.  

Imbue,  
Thank you for your solution.

Regards,

Mike
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Run code from text file in vb 1 56
VBA filters 2 50
message box in access 4 41
Looking for VB6 code to read SQL table export it to ascii 8 32
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now