I have the following code. The problem is, if i move the mouse in the picturebox, only the exact points of the polygon execute the me.text code. Otherwise, the contains method does not recognize the area of the polygon. I know this works for a rectangle, since it uses a rect structure, but I can't imagine this is not somehow simplified for polygons also. I really would like to solve this if someone can help please. So basically I want to move the mouse inside the polygon and make it detectable.
Code:
Dim point1 As New Point(110, 10)
Dim point2 As New Point(200, 10)
Dim point3 As New Point(210, 40)
Dim point4 As New Point(190, 60)
Dim point5 As New Point(140, 60)
Dim point6 As New Point(110, 50)
Dim point7 As New Point(110, 20)
Dim polygonPoints As Point() = {point1, point2, point3, point4, point5, point6, point7}
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
Dim p As Point = New Point(e.X, e.Y)
If polygonPoints.Contains(p) Then
Me.Text = "___TEST___"
Else
Me.Text = ""
End If
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
DrawPolygonPoint(e)
End Sub
Public Sub DrawPolygonPoint(ByVal e As PaintEventArgs)
' Create pen.
Dim yellowPen As New Pen(Color.Yellow, 1)
' Draw polygon to screen.
e.Graphics.DrawPolygon(yellowPen, polygonPoints)
End Sub