Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27513

[RESOLVED] I would like to make the area of a polygon selectable instead of just the points!

$
0
0
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


Viewing all articles
Browse latest Browse all 27513

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>