[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 514
  • Last Modified:

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

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!
1 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

NerdsOfTechTechnology ScientistAuthor Commented:
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

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now