Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Placing objects on a map (which is an image) 1

Status
Not open for further replies.

krinid

Programmer
Jun 10, 2003
356
CA
Short question:
How can I detect where on an image a user has clicked? (independent of user's screen resolution, so pixels are out)

Long question:
I have a map (which is merely an image) that I need to place objects on. What's a good way to go about this?

My current idea:
- import image into Excel (or some other Office application, if there's a benefit to it)
- when the image is clicked, add an object at the clicked point, getting details of the object from the user (and display it in a textbox, label, or something)

One problem, I'm not sure how I can detect the point the user clicked on the map and put an object there. Any ideas?

Another consideration is that the placing of these objects must be independent of the user's resolution mode, so any 'pixel' related methods can't be used. Are the positions of objects (.left, .top, .height, .width members) resolution independent?

If anyone has any good alternative approaches, I'd be interested in hearing them.
 
Simplest way is to convert the X,Y location to a percentage:
Code:
Private Sub Image1_MouseMove( _
                   ByVal Button As Integer, _
                   ByVal Shift As Integer, _
                   ByVal X As Single, _
                   ByVal Y As Single)
  With Image1
    TextBox1.Text = Y / .Height
    TextBox2.Text = X / .Width
  End With
End Sub
 
Zathras,
Good idea ! It's kind of nice also in that the map can change it's size w/o affecting the placement of the objects. Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top