GreenBar




Private Sub Form_Load()
'Vars for greenbar code

Dim i As Integer
Dim X1 As Long
Dim Y1 As Long
Dim X2 As Long
Dim Y2 As Long
Dim iTempHeight As Long
Dim iFontHeight As Long
Dim iBarHeight As Integer
Dim iNumberOfItems As Integer
Dim ldummy As Integer
Dim iTwipsPerPixelY As Long
'--- Code to load & display some sample data ---

Dim j As Integer
Dim itmX As ListItem
Dim ColHead As ColumnHeader
ListView1.ColumnHeaders.Add , , "This is Just a Simple Example"
ListView1.ColumnHeaders(1).Width = 3000

For j = 1 To 30
Set itmX = ListView1.ListItems.Add()
itmX.Text = "This is item number " & CStr(j)
Next j
'--- End sample data code ---

'***** Greenbar - Code to calc barsize & draw bars in the picture

'Makes sure your form's scalemode is set to twips

Me.ScaleMode = vbTwips
'Picturebox scalemode must be in pixels

picGreenbar.ScaleMode = vbPixels
picGreenbar.BorderStyle = 0 'none
picGreenbar.AutoRedraw = True
picGreenbar.Visible = False
picGreenbar.Font = ListView1.Font
iFontHeight = picGreenbar.TextHeight("|")
'3 line wide greenbars. 3 pixels (the "+3") is small fudge factor

'to keep the bars the right size

iBarHeight = (iFontHeight * 3) + 3
iTwipsPerPixelY = Screen.TwipsPerPixelY
iNumberOfItems = ListView1.ListItems.Count + 4
iTempHeight = iTwipsPerPixelY * (iFontHeight * iNumberOfItems)
'If the number of selections don't fill the listbox, make sure

'your background is still large enough You'll also need to

'modify these if you allow the listview to be resized.

If iTempHeight >= ListView1.Height Then
picGreenbar.Height = iTempHeight
Else
picGreenbar.Height = ListView1.Height
End If
picGreenbar.Width = ListView1.Width
X1 = 0
Y1 = 0
X2 = picGreenbar.ScaleWidth
Y2 = iBarHeight
For i = 0 To picGreenbar.ScaleHeight
If i Mod 2 = 0 Then
picGreenbar.Line (X1, Y1)-(X2, Y2), vbWhite, BF 'white bars - modify vbWhite to change bar color
Else
picGreenbar.Line (X1, Y1)-(X2, Y2), RGB(227, 241, 226), BF
'light green bars - modify RGB(x,x,x) to change bar color

End If
Y1 = Y2
Y2 = Y1 + iBarHeight
Next i
ListView1.Picture = picGreenbar.Image
End Sub










( greenbar.html )- by Paolo Puglisi - Modifica del 17/12/2023