Not a Member Yet,
Click here to Register

ID: 342
Viewed: 3332
Added: Aug 19, 2002
Snippet uploaded by: snippet
Written By: Unknown
Demo: Sorry, no demo

User Rated at: 0 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty


I drew onto the form, a map of hexagons that fills the whole form. What I wish to do is to know which Hexagon the user clicked. I used a loop of createPolygon api to create the Hexagons and stored each region in a variable Hex(I).
I also use the event Form_MouseMove to capture the location of the mouse when the Form_Click event is launched but I have no way to compare those coordinates with those of each hexagon region I created previously...
Any one have any suggestions, maybe I'm going about this all wrong???


Did you use the CreatePolygonRgn API call to store that handles of the hexagon's in the Hex() array that you speak of? If so you can use the PtInRegion API call to check if the user has clicked inside the polygon. Also you are going to need to use the Form_MouseDown event rather than the Form_Click event, here's some sample code....

Highlight all by clicking in box
Private Declare Function PtInRegion Lib "gdi32" (ByVal hRgn As Long, ByVal x As Long, ByVal y As Long) As Long

Highlight All
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim iCt As Integer
Dim lX As Long, lY As Long

If Button = vbLeftButton Then ' if user clicked the left mouse button

'Must convert coordinates from Twips to Pixels
lX = x / Screen.TwipsPerPixelX
lY = y / Screen.TwipsPerPixelY

For iCt = LBound(Hex) To UBound(Hex) ' Loop through each region handle

If Not PtInRegion(Hex(iCt), lX, lY) = 0 Then ' Are coordinates within Hexagon

Debug.Print "Region Number " & iCt & " Selected!"

End If

Next iCt

End If

End Sub;

No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.

Replying to a Comment...

Adding your comment. Please wait...

Thanks for adding your comment!. After further review it will be added.

There was a problem adding your comment. Please try again.

Please complete all the fields in the form before sending.

© 2002 - 2024 All Rights Reserved. Conditions
Do NOT follow this link or you will be banned from the site!