check if cursor is inside polygon (mousemove)

ridhwaans

Active member
Joined
Jun 1, 2012
Messages
34
Programming Experience
3-5
what is the code to create a polygon object to refer with a mouse event?
Suppose I want to create a polygon on a container in the form, and an event triggers when the user mouses over the polygon (i.e. msgbox)
do I have to define an element object of Polygon class for the mousemove event? or can I refer to this:

VB.NET:
Dim blackPen As New Pen(Color.Black, 1)
        Dim point1 As New Point(559, 732)
        Dim point2 As New Point(601, 731)
        Dim point3 As New Point(606, 979)
        Dim point4 As New Point(558, 961)
        Dim point5 As New Point(559, 960)
        Dim point6 As New Point(557, 904)
        Dim point7 As New Point(558, 904)
        Dim point8 As New Point(558, 840)
        Dim curvePoints As Point() = {point1, point2, point3, point4, _
        point5, point6, point7, point8}
        e.Graphics.DrawPolygon(blackPen, curvePoints)
 
You can create the polygon as a GraphicsPath (and draw that), and store it for reference, then using mouse events you check with GraphicsPath.IsVisible method to see if point is contained in the polygon.
 
Back
Top