Click inside a list of points to return a number
I created a list of points as the first section of my image map. There will eventually be 80+ sections each with their own number value.
If anybody can tell me how to make this particular section return a value of 20 to a label when the mouse is clicked inside the coordinates I laid out, that would be great!
vb.net Code:
Public Class Form1
Public Sub New()
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))
Me.InitializeComponent()
Me.PictureBox1.Image = My.Resources.Dartboard_unlabeled_svg
End Sub
Private Sub PictureBox1_mouseclick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseClick
End Sub
End Class
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...
Re: Click inside a list of points to return a number
Re: Click inside a list of points to return a number
That looks exactly like what I need!
Only thing is when using that code the image in the picture box doesn't show and the picture box blocks mouse clicks to get the value. When I moved the picture box out of the way I did get a value of 20. How do I make it so that the image shows and I can still get that 20 return when clicking over the picture box?
Re: Click inside a list of points to return a number
my code was using form mouse events.
just change it to picturebox mouse events
Re: Click inside a list of points to return a number
Quote:
Originally Posted by
.paul.
my code was using form mouse events.
just change it to picturebox mouse events
Working great now. Thanks so much!