Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By JohnH

Thread: check if cursor is inside polygon (mousemove)

  1. #1
    ridhwaans is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0
    Join Date
    Jun 2012
    Posts
    33
    Reputation
    14

    check if cursor is inside polygon (mousemove)

    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:

    Code:
    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)

  2. #2
    JohnH's Avatar
    JohnH is online now VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,206
    Reputation
    2369
    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.
    ridhwaans likes this.

  3. #3
    ridhwaans is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0
    Join Date
    Jun 2012
    Posts
    33
    Reputation
    14
    perfect, that works
    thank you JohnH

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking