Results 1 to 6 of 6

Thread: Click inside a list of points to return a number

Threaded View

  1. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Click inside a list of points to return a number

    you could use graphicspaths with a dictionary(of graphicspath, integer) like this:

    Code:
    Public Class Form1
    
        Dim sections As New Dictionary(Of Drawing2D.GraphicsPath, Integer)
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim pts As New List(Of PointF)() 's20 big
            pts.Add(New PointF(224, 75))
            pts.Add(New PointF(232, 131))
            pts.Add(New PointF(267, 131))
            pts.Add(New PointF(276, 75))
            pts.Add(New PointF(224, 75))
    
            Dim gp As New Drawing2D.GraphicsPath
            gp.AddPolygon(pts.ToArray)
    
            sections.Add(gp, 20)
        End Sub
    
        Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
            Dim kvp As KeyValuePair(Of Drawing2D.GraphicsPath, Integer) = sections.FirstOrDefault(Function(de) de.Key.IsVisible(e.Location))
            MsgBox(kvp.Value)
        End Sub
    
        Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
            Dim kvp As KeyValuePair(Of Drawing2D.GraphicsPath, Integer) = sections.FirstOrDefault(Function(de) de.Key.IsVisible(e.Location))
            Me.Text = (kvp.Value = 20).ToString
        End Sub
    
    End Class
    edit: the MouseMove code was just there for my testing purposes...
    Last edited by .paul.; May 5th, 2013 at 05:23 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width