I have a picturebox with a large picture:
In this picturebox various areas are colored using the ExtFloodFill()
API
Private Declare Function ExtFloodFill Lib "GDI32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long, ByVal wFillType As Long) As Long
The X and Y coordinates from which the FloodFills are started are somewhere in the area which has to be filled, but not in the exact center, or with the same offset for all areas, and neither are the areas the same shape or size. (That's why we love FloodFill)
I now want the users to interact with the picture by clicking on it and using the coordinates for specific actions corresponding to the area they clicked on.
For this I use the _MouseDown()
event:
Private Sub picfat_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim lngIndex As Long
lngIndex = CheckClick(mobjDet, x, y)
If lngIndex > -1 Then
With mobjDet(lngIndex)
.lngStat = 2 - .lngStat
SendCmd "det swico " & CStr(lngIndex) & "=" & CStr(.lngStat), wskDet
End With 'mobjDet(lngIndex)
End If
End Sub
Which calls CheckClick()
to determine which area the click was on:
Private Function CheckClick(obj() As FC_DET, sngX As Single, sngY As Single) As Long
Dim lngObj As Long
Dim lngIndex As Long
Dim sngWidth As Single, sngHeight As Single
sngWidth = 15
sngHeight = 15
lngIndex = -1
For lngObj = 0 To UBound(obj)
With obj(lngObj)
If sngWidth > 0 Then
If sngX > .sngX Then
If sngX < .sngX + sngWidth Then
If sngY > .sngY Then
If sngY < .sngY + sngHeight Then
lngIndex = .lngIndex
Exit For
End If
End If
End If
End If
End If
End With 'obj(lngObj)
Next lngObj
CheckClick = lngIndex
End Function
At this moment I use a square of 15x15 pixels to the bottom-right of the original X and Y coordinates, which works correctly if the user clicks on those coordinates.
The 15x15 square would work for the smallers squares in the picture if the X and Y coordinates of the FloodFill would be the upperleft corner of the small squares, but this is not the case, and as you can see there are other shapes as well as the small squares.
What I want to do is:
- Use the X and Y coordinates from the
_MouseDown()
event - Loop through my list of X and Y coordinates from the FloodFill starts
- Determine which FloodFill start corresponds to the X and Y coordinates from the MouseDown event
[EDIT]
For example:
- The center of the yellow floodfill in my picture is 500,160 (in the yellow between the white square and rectangle). The coordinates of this are
mobjDet(6).sngX
andmobjDet(6).sngY
- The user clicks somewhere in the yellow area above the white rectangle, for example at 495,53
- How can I couple the X and Y of the _MouseDown() event with the index (6) of my FloodFill udt ?
That way I can find out which area the user clicked on in the picture.