|
-
May 5th, 2013, 05:05 PM
#1
Thread Starter
New Member
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
-
May 5th, 2013, 05:19 PM
#2
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.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 5th, 2013, 05:43 PM
#3
Re: Click inside a list of points to return a number
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 5th, 2013, 05:53 PM
#4
Thread Starter
New Member
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?
-
May 5th, 2013, 05:59 PM
#5
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 5th, 2013, 06:14 PM
#6
Thread Starter
New Member
Re: Click inside a list of points to return a number
 Originally Posted by .paul.
my code was using form mouse events.
just change it to picturebox mouse events
Working great now. Thanks so much!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|