I have a child form that creates a bitmap from an image and also draws different colored rectangles on the new bitmap. My goal is to have all of one single color (blue) rectangles display a tooltip of it's own when moused over. Now, I'm relative new at VB and there may be an easier way, but I did accomplish what I wanted by adding labels/tooltips that overlay the drawn colored rectangles as they were being drawn.
My problem lies in that the user can edit the color database, thus adding or removing those blue colored rectangles, the bitmap image updates the colors, and the label/tootips if adding another blue rectangle......but when updating causes a blue rectangle to change to another color, my label/tooltip remains.
I've search for ways to remove the labels, but I'm not having any success...In testing the form should contain 1 picturebox and 10 labels/tooltips, but when counting the controls on the form (child0.Controls.Count) I only get 1
My problem lies in that the user can edit the color database, thus adding or removing those blue colored rectangles, the bitmap image updates the colors, and the label/tootips if adding another blue rectangle......but when updating causes a blue rectangle to change to another color, my label/tooltip remains.
I've search for ways to remove the labels, but I'm not having any success...In testing the form should contain 1 picturebox and 10 labels/tooltips, but when counting the controls on the form (child0.Controls.Count) I only get 1
Code:
Public Sub rebuildForm1(ByVal buttonClicked As Integer)
Dim conn As OleDbConnection = GetDbConnection()
Dim tblStatus As String = "lot_status"
Dim query As String = "SELECT * FROM " & tblStatus
Dim cmd As New OleDb.OleDbCommand(query, conn)
Dim rowItems As OleDbDataReader
rowItems = cmd.ExecuteReader
Dim blockY As Integer
Dim lotX As Integer
Dim spaceX As Integer
Dim status As Integer
Dim section As String
Dim x As Integer
Dim y As Integer
Dim Yoffset As Integer = (-4)
Dim rh As Integer = 9 'sets height of rectangle)
Dim appPath As String
appPath = System.Windows.Forms.Application.StartupPath
Dim available As Integer = 0
Dim unoccupied As Integer = 0
Dim occupied As Integer = 0
Dim unknown As Integer = 0
Dim nosale As Integer = 0
Dim nostatus As Integer = 0
Dim bmp0 As New Bitmap(appPath & "\images\map.png")
Dim bmp1 As New Bitmap(appPath & "\images\map.png")
Dim bmp2 As New Bitmap(appPath & "\images\map.png")
Dim bmp3 As New Bitmap(appPath & "\images\map.png")
Dim bmp4 As New Bitmap(appPath & "\images\map.png")
Dim bmp5 As New Bitmap(appPath & "\images\map.png")
Dim bmp6 As New Bitmap(appPath & "\images\map.png")
Dim w As Integer
Dim h As Integer
Dim clr As Object = "" 'color
Dim block As String
Dim lot As String
Dim space As String
'get rows from DB
Do While rowItems.Read
blockY = rowItems!BlockY
lotX = rowItems!LotX
spaceX = rowItems!SpaceX
status = rowItems!Status
section = rowItems!Section
block = rowItems!block
lot = rowItems!lot
space = rowItems!space
Select Case status
Case 0
clr = Color.DeepSkyBlue
available = available + 1
Case 1
clr = Color.Yellow
unoccupied = unoccupied + 1
Case 2
clr = Color.LimeGreen
occupied = occupied + 1
Case 3
clr = Color.Red
nosale = nosale + 1
Case 4
clr = Color.Orange
unknown = unknown + 1
Case 5
nostatus = nostatus + 1
clr = Color.SaddleBrown
End Select
y = blockY + Yoffset ' row location
y = y - 12 'need to subtract 12 because I cropped the image and lost 12 from top
If section = "s" Then
x = (lotX + spaceX) * (-1) + 697 'column location for southern section of map (subtracted 5 after cropping image 5 from left side)
Else : x = (lotX + spaceX) + 734 'column location for northern section of map (subtracted 5 after cropping image 5 from left side)
End If
' draw the status blocks as indicated by DB
For w = 1 To 6
For h = 1 To rh
bmp6.SetPixel(x + w, y + h, clr)
Next
Next
If status = 0 Then
drawTTlbls(block, lot, space, section, blockY, lotX, spaceX)
End If
Loop
'draw the complete image to forms
child0.PictureBox1.Image = bmp0
If conn.State = ConnectionState.Open Then
conn.Close()
End If
End Sub
Public Sub drawTTlbls(ByVal block As String, ByVal lot As String, ByVal space As String, ByVal section As String,
ByVal blockY As Integer, ByVal lotX As Integer, ByVal spaceX As Integer)
Dim x As Integer
Dim y As Integer
Dim Yoffset As Integer = (-4)
y = blockY
x = (lotX + spaceX) * (-1) + 698
Dim lblSpace0 As New Label()
With lblSpace0
.Location = New Point(x, y)
.Size = New Size(6, 9)
.BackColor = Color.DodgerBlue
.Name = "ToolTip0"
' .Visible = False
'.TabIndex = 0
'.TextAlign = ContentAlignment.MiddleCenter
'.Tag = "Space"
.Text = ""
End With
child0.PictureBox1.Controls.Add(lblSpace0)
Dim tt0 As New ToolTip()
Dim ttTxt0 As String = block & " - " & lot & " - " & space
tt0.SetToolTip(lblSpace0, ttTxt0)
End Sub