Grid with a defined amount of x-axis and y-axis lines in Visual Basic 2008 Express Edition plus value output.

Posted on 2009-04-26
Last Modified: 2013-11-27
1.) I would like to limit the amount of x-axis to 13 lines and the y-axis lines to 16 lines
2.) I would like two labels to show the current position on the grid THE MOUSE is in BASED ON GRID VALUES X and Y even if there is no point there.
E.G.    X: 1     Y:10
3.) I would like a label to be shown above any set point of the current X, Y value (in small font) when hovered over.

500 points to the solver!
Question by:NerdsOfTech
    LVL 6

    Accepted Solution

    At a very high level, you need to handle the MouseMove event of the container you're drawing in, calculate the cell the pointer is in (since you know the size of a cell it's easy) and then display a tooltip near the mouse position.

    I don't have the time right now to properly test and complete the code, but you should be able to take it from here. Further ideas could be to show the tooltip in a different position if the mouse is near a border, so it's always properly visible, nicer drawing of the tooltip (rounded borders, gloss) etc.

    Assuming the code is similar to the one from the related solution:

    Private tooltipText as String
    Private xMouse as Integer, yMouse as Integer
    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseMoveEventArgs) Handles PictureBox1.MouseMove
      xMouse = e.X
      yMouse = e.Y
      Dim x As Integer = Math.Round(e.X / GridDist)
      Dim y As Integer = Math.Round(e.Y / GridDist)
      tooltipText = x & ", " & y
    End Sub
    Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
      <... existing function contents ...>
      Dim s As System.Drawing.SizeF = g.MeasureString(tooltipText, new System.Drawing.Font("Arial", 12))
      Dim r As RectangleF = new RectangleF(xMouse - 15, yMouse - 15, s.Width + 2, s.Height + 2)
      g.FillRectangle(System.Drawing.Brushes.Lavender, r)
      g.DrawRectangle(System.Drawing.Pens.Gray, r)
      e.Graphics.DrawString(tooltipText, new System.Drawing.Font("Arial", 12), System.Drawing.Brushes.Black, xMouse - 14, yMouse - 14)
    End Sub

    Open in new window

    LVL 19

    Author Closing Comment

    Thanks. I got it work before I read your post. However you are correct in correctly using MouseMove event to track the mouse position. I will be connecting another question to this one to figure out how to make the point "shape" into different shapes. If you want you will be able to participate by clicking the right arrow near this question. =NerdsOfTech

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now