Question

Picturebox with Dartsboardimage - after clicked on, know what value?

Asked by: Paurths

Hi,

Assume i have a form with a picturebox on it,
the image in the picturebox is a dartboard. (Darts as in England --> image of dartboard here: http://www.amisane.org/images/dartboard2.jpg

What i would like to accomplish: if the user clicks somewhere on the image i want to know where on the board the user clicked so i can allow points.

I know how to make polygons on the picturebox, so i thought i could use that.
First of all, there are alot (very very alot lol) polygons to be created,
and second, how do i know on what polygon the user clicked... (can a polygon be named? or would i just use the X,Y coordinates to find out in what polygon the user clicked? --> seems that would slow down the code very much)

I don't know if i'm following the correct way to do this, let alone i would be aware of another solution...

Btw, if this can be done in VB6, that would also be good.
.Net would be really great!

cheers
Ricky

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2007-10-03 at 12:08:37ID22870236
Tags

Dartsboard Points Polygon Picturebox

,

picturebox

,

clicked

Topics

Microsoft Visual Basic.Net

,

Visual Basic Programming

Participating Experts
2
Points
500
Comments
11

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. PictureBox leaks?
    Could it be that the vb PictureBox has a memory leak? I tried the following - Start Task Manager and look at Performance. MEM Usage... In my code, the following is executed: Set SomePictureBox.Picture = (etc.) MEM Usage jumps up, as expected. Then, I try to destroy the pi...
  2. How to Convert World Coordinates to the x,y coords of a …
    I am sorry for my poor English. I need to Convert World Coordinates to the x,y coords of a picture box. For example, If I set a point in a map, its world coordinate is (80E,30N), to the the upper left corner of the picturebox, how do I get the x,y cords of other points. Cou...
  3. picturebox
    i have a picturebox and a multiline richtextbox. the text in it would get printed in the picturebox. the problem is if the text in the richtextbox automatically word wraps then the text in the picturebox gets printed in a single line. So the text is printed beyond the screen....

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: craskinPosted on 2007-10-03 at 12:13:19ID: 20009181

You could do something like this:

Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e _
     As
System.Windows.Forms.MouseEventArgs) Handles _
    MyBase.MouseDown
    ' Clear previous results.
    Dim gr As Graphics = Me.CreateGraphics()
    DrawGraph(gr)

    ' Convert the X coordinate into world coordinates.
    Dim m As Matrix = gr.Transform()
    m.Invert()
    Dim pts() As PointF = {New PointF(e.X, e.Y)}
    m.TransformPoints(pts)
    Dim x0 As Single = pts(0).X
    Dim y0 As Single = pts(0).Y

'do something with X,Y
   
End Sub

 

by: craskinPosted on 2007-10-03 at 12:13:51ID: 20009189

sorry, ignore the CreateGraphics part.

 

by: PaurthsPosted on 2007-10-03 at 12:30:37ID: 20009327

Hi craskin,
thank you for your very fast response!

It errors out, saying "type matrix is not defined"...
(i am kinda new to .Net lol)

G's
Ricky

 

by: craskinPosted on 2007-10-03 at 12:33:42ID: 20009356

you need to import the 2ddrawing library

Imports System.Drawing2D

 

by: PaurthsPosted on 2007-10-03 at 13:42:28ID: 20009889

Hi, you wrote to ignore the  CreateGraphics part, but then gr is not declared...

 

by: Idle_MindPosted on 2007-10-03 at 13:54:27ID: 20009975

Use Polar coordinates.  Then you can "define" the areas of the board as regions between a start and stop angle and a start and stop distance from the center of the dartboard:
http://en.wikipedia.org/wiki/Polar_coordinates

 

by: PaurthsPosted on 2007-10-03 at 14:22:46ID: 20010174

Hi Idle_mind,

looks very interesting,
but i don't have a clue on how to start coding that...
Do you have an example?


About polygons
Can polygons be given a name when created?

'This example draws a polygon in the Triple 20 area

Private Sub cmdDraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDraw.Click
        Dim g As System.Drawing.Graphics
        Dim pen1 As New System.Drawing.Pen(Color.Blue, 3)
        Dim p(7) As System.Drawing.Point

        p(0).X = 365
        p(0).Y = 195
        'Draw again, or there will be a line from the left upper corner of the picturebox to the polygon
        p(1).X = 365
        p(1).Y = 195
        p(2).X = 393
        p(2).Y = 194
        p(3).X = 419
        p(3).Y = 195
        p(4).X = 416
        p(4).Y = 208
        p(5).X = 394
        p(5).Y = 207
        p(6).X = 368
        p(6).Y = 207
        'Do the first point again, to close the polygon
        p(7).X = 365
        p(7).Y = 195

        g = PictureBox1.CreateGraphics
        g.DrawPolygon(pen1, p)

    End Sub


Is there anyway to know if the user clicked the polygon?

I was thinking in the lines of like a clickable map in HTML.
The part the mouse hovers over "lights up", like a link. When clicked the link would "send" a value to a subroutine or something..... ???

cheers
Ricky

 

by: PaurthsPosted on 2007-10-03 at 14:58:39ID: 20010380

Come to think,
i can create a HTML-page, with the image on it,
create all the area shapes (all the polygons) and put links to it

The question is then, how do i put this page into a .net form?
And, if that can be done, how do i get the link-value into my .net form (code) after i click a polygon in the image in the html-page (which should be inside my form)?

Anyone?

cheers
Ricky

 

by: Idle_MindPosted on 2007-10-03 at 15:17:16ID: 20010487

If you want to define the darboard as multiple polygons then here is an approach that may work for you:

Imports System.Drawing.Drawing2D
Public Class Form1

    Private polygons As New ArrayList
    Private polygonNames As New Hashtable
    Private lastPolygon As GraphicsPath = Nothing

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim gp As New GraphicsPath


        Dim p(7) As System.Drawing.Point
        p(0).X = 365
        p(0).Y = 195
        p(1).X = 365
        p(1).Y = 195
        p(2).X = 393
        p(2).Y = 194
        p(3).X = 419
        p(3).Y = 195
        p(4).X = 416
        p(4).Y = 208
        p(5).X = 394
        p(5).Y = 207
        p(6).X = 368
        p(6).Y = 207
        p(7).X = 365
        p(7).Y = 195
        gp = New GraphicsPath
        gp.AddPolygon(p)
        polygons.Add(gp)
        polygonNames.Add(gp, "Triple 20 Area")

        ' create more polygons just like above...
        ' ...and add them to "polygons" and "polygonNames"
    End Sub

    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        Dim curPolygon As GraphicsPath = Nothing
        For Each polygon As GraphicsPath In polygons
            If polygon.IsVisible(e.X, e.Y) Then
                curPolygon = polygon
                Exit For
            End If
        Next
        If Not (curPolygon Is Nothing) Then
            If Not (lastpolygon Is curPolygon) Then
                lastPolygon = curPolygon
                PictureBox1.Refresh()
                Label1.Text = polygonNames.Item(curPolygon)
            End If
        ElseIf Not (lastPolygon Is Nothing) Then
            lastPolygon = Nothing
            Label1.Text = ""
            PictureBox1.Refresh()
        End If
    End Sub

    Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
        If Not (lastPolygon Is Nothing) Then
            Dim pen1 As New System.Drawing.Pen(Color.Blue, 3)
            e.Graphics.DrawPath(pen1, lastPolygon)
            pen1.Dispose()
        End If
    End Sub

    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        Dim curPolygon As GraphicsPath = Nothing
        For Each polygon As GraphicsPath In polygons
            If polygon.IsVisible(e.X, e.Y) Then
                curPolygon = polygon
                Exit For
            End If
        Next
        If Not (curPolygon Is Nothing) Then
            MessageBox.Show(polygonNames.Item(curPolygon))
        End If
    End Sub

End Class

 

by: PaurthsPosted on 2007-10-03 at 15:26:10ID: 20010530

Idle_mind,

you are the hero of the day!!!!

WOW!!!
Really very impressive!!!

Thanks a million!!!

Cheers
Ricky

 

by: Idle_MindPosted on 2007-10-03 at 15:31:46ID: 20010560

"Btw, if this can be done in VB6, that would also be good.
.Net would be really great!"

This can also be done in VB6 but you would have to use lower level GDI APIs to create the polygons, do the "hit testing", and paint them into your PictureBox.

If you have VB.Net 2005 then you can use the Generic List instead of an ArrayList.

If you want to really go with the concept then write a custom class to encapsulate the GraphicsPath.  Then you can store a name AND a value for each path.  This will make the code cleaner since you wouldn't seperate structures to hold the paths, names and values...

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...