Mapping an Image

  • Thread starter Michael San Filippo
  • Start date
M

Michael San Filippo

I want to have an image that the user can click on and it will record for
that record the location of the click on the image.

Think if a map of the world where you can click a spot on the world where
the record (person) is from.

anytime the form is opened, the spot would move to that x,y grid on the
world. would also like to color code the spot - red. green, yellow, etc

Thanks
JamesSF
 
B

Bryan Reich [MSFT]

Michael,

Here's what I did to get it working. Assume Form1 is attached to a table
with an autonumber ID and X and Y fields that are numbers.
I made a form and placed an image control on it (Image1). I also created two
non visible fields (Visible property set to false) called YCoord and XCoord
to hold the X and Y coordinates of the click. These fields are bound to the
X and Y fields in the table. Lastly, I created a Box object on the form and
made it quite small. I called this "box".

Try out the following code and adapt to your needs. Any questions, feel free
to post back and ask:

' form has had record change, adjust the marker for the new record's data
Private Sub Form_Current()
Call UpdateMarker
End Sub

' form first loaded, place the marker according to the current record data
Private Sub Form_Load()
Call UpdateMarker
End Sub

' Image 1 was clicked and the mouse button released.
' Calculate the new position of the click and store in the
' proper controls
Private Sub Image1_MouseUp(Button As Integer, Shift As Integer, X As Single,
Y As Single)

XCoord.Value = X
YCoord.Value = Y
' update the position and color of the box indicating the click location
Call UpdateMarker

End Sub

Private Sub UpdateMarker()
Dim X, Y As Single

' get the coordinates of the click for this record
If Not IsNull(XCoord.Value) And XCoord.Value <> "" Then
X = CSng(XCoord.Value)
Else
X = 0
End If

If Not IsNull(YCoord.Value) And YCoord.Value <> "" Then
Y = CSng(YCoord.Value)
Else
Y = 0
End If

' place the marker
box.Left = Image1.Left + X
box.Top = Image1.Top + Y

' depending on which quadrant the marker is in, set the color
accordingly
If X < 1000 And Y < 1000 Then
box.BorderColor = RGB(240, 0, 0)
ElseIf X >= 1000 And Y < 1000 Then
box.BorderColor = RGB(0, 240, 0)
ElseIf X < 1000 And Y >= 1000 Then
box.BorderColor = RGB(0, 0, 240)
Else
box.BorderColor = RGB(240, 240, 240)
End If

End Sub

' may be redundant. Experiment regarding whether these are needed or not.
Private Sub XCoord_AfterUpdate()
Call UpdateMarker
End Sub
Private Sub YCoord_AfterUpdate()
Call UpdateMarker
End Sub
 
B

Bryan Reich [MSFT]

Just to clarify, I actually meant I created a Rectangle object and called it
"box". Also, I created two non-visible TextBoxes (i used the word fields
instead in my first post which isn't the best terminology). Oh, and James,
sorry I called you Michael, I was looking at your 'from' field. :)
 
M

Michael San Filippo

thanks a bunch worked like a charm!

Bryan Reich said:
Just to clarify, I actually meant I created a Rectangle object and called it
"box". Also, I created two non-visible TextBoxes (i used the word fields
instead in my first post which isn't the best terminology). Oh, and James,
sorry I called you Michael, I was looking at your 'from' field. :)
 
M

Michael San Filippo

OK - One more thing -

How would you say would be the best way to display an unlimited amount of
boxes.

For example - someone chooses 3 diff places - the main pic of the world
needs to have 3 boxes now - and what about 4 and 5 and so on.

How could I do that? is there a way I can spawn off multiple copies of the
box if they click?
 
B

Bryan Reich [MSFT]

James,
That's a very good question. It seems to me your biggest problem in this
case would be the fact that the database where you are storing this data
would not have a dynamic number of columns, so where would the additional
coordinates go? You might be able to dynamically generate rectangle objects,
but table columns would be a completely different thing.
Now, if you wouldn't mind setting an upper limit on the number of boxes,
then I think the best solution would be to have all of the coordinates in
your table, and maybe make the defaults -1,-1 (or some other invalid value),
and produce a cooresponding number of boxes on your form. Then, in the code,
if the field out of the table says the coordinates are -1,-1 for a given
box, hide it, else show it. And then do the placements.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of any included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


Michael San Filippo said:
OK - One more thing -

How would you say would be the best way to display an unlimited amount of
boxes.

For example - someone chooses 3 diff places - the main pic of the world
needs to have 3 boxes now - and what about 4 and 5 and so on.

How could I do that? is there a way I can spawn off multiple copies of the
box if they click?
Bryan Reich said:
Just to clarify, I actually meant I created a Rectangle object and
called
 

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