defining mouseenter, mouseleave, mousehover

ridhwaans

Active member
Joined
Jun 1, 2012
Messages
34
Programming Experience
3-5
With the absence of the System.windows.shapes (PresentationFramework.dll), I have defined my own polygon class with custom events handlersand constructor for a particular application. My question is, how can I code the mouseenter, mouseleave, and mousehover event definitions based on the polygon's coordinates list for use and eventraise?
 
You would have to handle the appropriate events of the control that the shapes are drawn on and then determine which events of which shape(s) to raise. It might not be a bad idea to add a property to your class to refer to the control it's being drawn on. It can then handle those events itself.
 
You would have to handle the appropriate events of the control that the shapes are drawn on and then determine which events of which shape(s) to raise. It might not be a bad idea to add a property to your class to refer to the control it's being drawn on. It can then handle those events itself.

Thank you jmcilhinney
At the moment, a loop in the mousemove event in the picturebox control checks if the cursor is inside any of the polygons from myClass.PolygonCollection, using the isAt defined bool function of the polygon class (after the polygon shape(s) are drawn from picturebox paint event and invalidate of course)
VB.NET:
Private Sub picture_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)

        For Each stub As stubPolygon In myClass.PolygonCollection
            If stub.IsAt(e.X, e.Y) Then
                // DO STUB
               Exit For
            End If
        Next

    End Sub

Could you please return an example of how the class property refers to the control it's being drawn on for event raise?
Can it start by moving the isAt() loop check to the mouseenter and mouseleave picturebox control event? :
VB.NET:
Class prog
Private Sub picture_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles picture.MouseEnter
For Each stub As stubPolygon In myClass.PolygonCollection
            If stub.IsAt(e.X, e.Y) Then
               stubpolygon.contains = true??
               Exit For
            End If
        Next
    End Sub

Private Sub picture_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles picture.MouseLeave
For Each stub As stubPolygon In myClass.PolygonCollection
            If stub.IsAt(e.X, e.Y) Then
                stubpolygon.contains = true??
               Exit For
            End If
        Next
    End Sub
End Class

Class stubPolygon
...
 Public Property contains()
        Get

        End Get
        Set(ByVal value)

        End Set
    End Property
...
End Class
 
Last edited:
Back
Top