I am working on a project where I need to be able to click on a map (which I have in a picturebox) and get the point that I clicked on. Is there any way to do this using VB? Thanks for any help in advance!
It might be a bit of a low tech solution but you could place frames or invisble image or pictureboxes on top of your picture and depending on where the user clicks on you picture they are actually cliclking on an invisible control which has been programmed to get the required point - I hope I've explained that properly....
Hi DeeDee[/b}
what do your mean by 'get'? the coordinates? the color of the pixel?
This will give you both:
----------------------------------------------------------
Private Declare Function GetPixel Lib "gdi32.dll" (ByVal hdc As Long, ByVal nXPos As Long, ByVal nYPos As Long) As Long
Private Sub Form_Load()
Picture1.ScaleMode = vbPixels
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
MsgBox " You clicked at: " & CStr(x) & " " & CStr
MsgBox " the color of the pixel you clicked is " & CStr(GetPixel(Picture1.hdc, CLng(x), CLng))
End Sub
----------------------------------------------------------
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
Sunaj's answer gives you just that! Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first
'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
I guess the best method depends on what you want to do....
What do you want to do?
You can load the picture from a file into a certain position:
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.PaintPicture LoadPicture("c:\tmp\jdraw.bmp", X, Y
End Sub
Or you can use the Bitblt to move a picute/ part of a picture around:
I have different maps that will be opened in the picturebox from a file. I need the latitude/longitude coordinates of the map to be the points that the user is clicking on. I don't even know if that is possible or not. That's why I need to be able to set the corner coordinates so they equal the lat/long of the map that is open in the picbox. Does that make sense??
DeeDee
That is indeed possible. However, you need to know which project the map is draw in.
The simples is a latitude-longitude plot (but it is rarely used because the distortion for high latitudes is large). If you know which projection is used, I might be able to help you.
Solutiuon for the lat-lon projection:
**************
Dim MaxX As Integer, MaxY As Integer, MinX As Integer, MinY As Integer 'the pixel coordinates of the map
Dim alon As Single, alat As Single, blat As Single, blon As Single 'the geographic coordinates of the map
'set the 8 parameter to their respective values here...
'The solution is 2 linear equations, calculate the coefficients:
alon = (MinX - MaxX) / (MinLon - MaxLon)
blon = MaxX - alon * MaxLon
'Calculate lon from coordinate
Public Function GetLon(X As Single) As Single
GetLon = (X - blon) / alon
End Function
'Calculate lat from coordinate
Public Function GetLat(Y As Single) As Single
GetLat = (Y - blat) / alat
End Function
************
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.