How to grab mouse XY coordinates

T

Terrell Miller

one of our scientists asked this question, any help
greatly appreciated:

how can you capture the XY coordinates of the mouse at any
given time? We'd like to do this for a map image on a form
so when the user clicks on a specific spot we can pull up
data for that state or city. To do that we'd need to know
where the pointer was when teh mouseclick occurred.

TIA,

Terrell
 
D

Dirk Goldgar

Terrell Miller said:
one of our scientists asked this question, any help
greatly appreciated:

how can you capture the XY coordinates of the mouse at any
given time? We'd like to do this for a map image on a form
so when the user clicks on a specific spot we can pull up
data for that state or city. To do that we'd need to know
where the pointer was when teh mouseclick occurred.

TIA,

Terrell

Event procedures for the MouseDown event receive the X and Y coordinates
among their arguments. For example,

Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X
As Single, Y As Single)
 
J

Jeff Bennett

From: Terrell Miller ([email protected])
Newsgroups: microsoft.public.access.forms
Date: 2004-08-26 15:17:03 PST

one of our scientists asked this question, any help
greatly appreciated:

how can you capture the XY coordinates of the mouse at any
given time? We'd like to do this for a map image on a form
so when the user clicks on a specific spot we can pull up
data for that state or city. To do that we'd need to know
where the pointer was when teh mouseclick occurred.



OK - it's easy in Access to get the X/Y Coordinates at any time.
Let's say your map image is inside an Image control.
You can trap the MouseUp, MouseDown or MouseMove
events and read the X and Y parameters within this event.

For example:

Private Sub Image0_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
' here you have full access to X and Y
End Sub

I hope this is helpful and meets your needs.

Note however that I would suggest you may want to consider
using a commercial component such as our MetaDraw control
which is specifically designed for what you are trying to do.

To see an example take a look at our web site
www.bennet-tec.com
Click on MetaDraw and then about 2 inches from
the bottom of the page click on MD Map demo

With MetaDraw for instance you can define hotspot regions
of any shape ( these shapes can be created by code or by
drawing on the control ) and you can associate data with each
hotspot area ( for instance the name of the states and cities
or the populations - in fact you can have multiple bits of data
for each area. You can also assign URLs to each area
and have MetaDraw automatically direct IE to load a web page
based on a user click or double click. Or You can trap hotspot
events when user moves over or clicks on an area - then read
the associated data and take the appropriate action.

MetaDraw will also allow you to Zoom and scroll ( and of course
the hotspots are automatically moved with the image ) and you
can dynamically modify the image ( add or move icons or shapes
on top of your map. You can even allow the user to add his
own annotations.

Again if my suggestion on getting X and Y in Mouse events
of standard controls meets your needs - GREAT,
otherwise I'd be happy to answer any questions you may
have about MetaDraw and to get you started with an evaluation
so you can try it out in Access directly

Jeff Bennett
(e-mail address removed)

* Bennet-Tec Information Systems, Inc
* 50 Jericho Tpk, Jericho, NY 11753
* Phone 516 997 5596, Fax - 5597
* RELIABLE Components Make You Look Sharp!
* TList/Pro * ALLText HT/Pro * MetaDraw *
* Custom Software Development Services Too.
* WWW.Bennet-Tec.Com

=================== ===================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top