Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Problem with detecting points on screen

Problem with detecting points on screen

Scheduled Pinned Locked Moved Visual Basic
helpdatabasegraphicsdata-structures
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    carrigart
    wrote on last edited by
    #1

    Hi i have a problem that is making me scratch my head until it hurts. Hopefully someone can help. Well in my project I have a graph were I plot information from a database. Anyways, when I draw my data to the screen I add each point to an arraylist. I use an arraylist since the number of points can vary. So I have my points drawn on screen so next is were my problem comes in. What I want to happen is when the mouse pointer goes over any of my points on my graph, then a small box pops up with more information. So in my mousemove event I have code as follows For Each p As Point In myCoordinatesArrayL gPath.AddEllipse(p.X, p.Y, 30, 30) If gPath.IsVisible(mouse.X, mouse.Y) Then 'Then make my small window pop up Else 'Do nothing or close small window if its up End If Next So im taking the points from my arraylist and adding an ellipse to a graphics path. Then I check the graphics path 'IsVisible' function if the mouse's x and y are over it. I have mixed results with this so far. Some strange and unexpected things have happened. I can get the window to pop up but sometimes it doesn't. I have done a bit of error checking were I have placed two labels on my form and I increment a number when ever the mouse is not over the points and then increments the other number when the mouse pointer is over the point. This has unexpected results such as when I have only one point on the screen and i move the mouse over the point then both label increment and when i have more than one point on the screen, its works as expected except for the first point on my graph where is produces the same problem. Hope you can make sense of this. Is there a better way to do what im trying to do. Any suggestions. Thanks for your help

    D 1 Reply Last reply
    0
    • C carrigart

      Hi i have a problem that is making me scratch my head until it hurts. Hopefully someone can help. Well in my project I have a graph were I plot information from a database. Anyways, when I draw my data to the screen I add each point to an arraylist. I use an arraylist since the number of points can vary. So I have my points drawn on screen so next is were my problem comes in. What I want to happen is when the mouse pointer goes over any of my points on my graph, then a small box pops up with more information. So in my mousemove event I have code as follows For Each p As Point In myCoordinatesArrayL gPath.AddEllipse(p.X, p.Y, 30, 30) If gPath.IsVisible(mouse.X, mouse.Y) Then 'Then make my small window pop up Else 'Do nothing or close small window if its up End If Next So im taking the points from my arraylist and adding an ellipse to a graphics path. Then I check the graphics path 'IsVisible' function if the mouse's x and y are over it. I have mixed results with this so far. Some strange and unexpected things have happened. I can get the window to pop up but sometimes it doesn't. I have done a bit of error checking were I have placed two labels on my form and I increment a number when ever the mouse is not over the points and then increments the other number when the mouse pointer is over the point. This has unexpected results such as when I have only one point on the screen and i move the mouse over the point then both label increment and when i have more than one point on the screen, its works as expected except for the first point on my graph where is produces the same problem. Hope you can make sense of this. Is there a better way to do what im trying to do. Any suggestions. Thanks for your help

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      You creating an ellipse for every point in the graph every time the mouse moves?? Wouldn't it be easier to just track the mouse movement, mapping it to the closest point in the X axis, then just create the one ellipse to see if the mouse is in it? Also, the code looks incomplete. Are you Disposing the GraphicsPath you created when you're done with it?? Are you creating a new one every time you iterate through this loop?? You don't need to.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008

      C 1 Reply Last reply
      0
      • D Dave Kreskowiak

        You creating an ellipse for every point in the graph every time the mouse moves?? Wouldn't it be easier to just track the mouse movement, mapping it to the closest point in the X axis, then just create the one ellipse to see if the mouse is in it? Also, the code looks incomplete. Are you Disposing the GraphicsPath you created when you're done with it?? Are you creating a new one every time you iterate through this loop?? You don't need to.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

        C Offline
        C Offline
        carrigart
        wrote on last edited by
        #3

        Hi, Not sure I know what you mean. So i think that for every point in my arraylist that I should check its x coordinate against the mouse x coordinate and then if it does , then i should add the ellipse to my graphics path. This is what I've tried but its not really working for me For Each p As Point In myCoordinatesArrayL If p.X = mouse.X Then gPath.AddEllipse(p.X, p.Y, 30, 30) If gPath.IsVisible(mouse.X, mouse.Y) Then 'code for displaying my window End If Else 'do nothing or close my window End If Next I dont have code to dispose the graphicsPath here but in my forms closing method. Is this right Thanks for your time

        D 1 Reply Last reply
        0
        • C carrigart

          Hi, Not sure I know what you mean. So i think that for every point in my arraylist that I should check its x coordinate against the mouse x coordinate and then if it does , then i should add the ellipse to my graphics path. This is what I've tried but its not really working for me For Each p As Point In myCoordinatesArrayL If p.X = mouse.X Then gPath.AddEllipse(p.X, p.Y, 30, 30) If gPath.IsVisible(mouse.X, mouse.Y) Then 'code for displaying my window End If Else 'do nothing or close my window End If Next I dont have code to dispose the graphicsPath here but in my forms closing method. Is this right Thanks for your time

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          No, you have to do a little math to figure out which point the X coord is NEAREST to on the graph. In your method, the mouse has to be EXACTLY on the point your looking for, not around it. If you have 3 points on the graph at 50, 75 and 100, you take the mouse X coord, say 80, then check it against the X coord of the points on the graph, plus or minus say 10. Doing the math is FAR faster than creating a graphics path to do the test for you.

          For Each p As Point In myCoordinatesArrayL
          If p.X - mouse.X <= 1- Then
          ' You don't even need the GraphicsPath since you just
          ' found the point you're looking for!
          ' If you really needed to, you can do the same test for the Y coordinate in here.
          End If
          Next

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008

          C 1 Reply Last reply
          0
          • D Dave Kreskowiak

            No, you have to do a little math to figure out which point the X coord is NEAREST to on the graph. In your method, the mouse has to be EXACTLY on the point your looking for, not around it. If you have 3 points on the graph at 50, 75 and 100, you take the mouse X coord, say 80, then check it against the X coord of the points on the graph, plus or minus say 10. Doing the math is FAR faster than creating a graphics path to do the test for you.

            For Each p As Point In myCoordinatesArrayL
            If p.X - mouse.X <= 1- Then
            ' You don't even need the GraphicsPath since you just
            ' found the point you're looking for!
            ' If you really needed to, you can do the same test for the Y coordinate in here.
            End If
            Next

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008

            C Offline
            C Offline
            carrigart
            wrote on last edited by
            #5

            Thats great. Thanks for your help. Never even thought of that. My inexperience is showing anyway. Thanks again. :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups