Visual Basic / Games / Polygon click
Snippet details
ID: 342
Viewed: 1243
Added: 2002-08-19
Version:
Question:
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???
Answer:
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....
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???
Answer:
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....
General Details
Snippet uploaded by: snippet
Email : webmaster@snippetlibrary.com
Snippet By: Unknown
| Snippet By: | Unknown |
| Declarations | |
| Code | |
| Highlight All | |
No Reviews to show
