Public Sub SetListViewColor(Lv As ListVIEw, picBg As PictureBox, LvCount As Long)
'Author:深夜的樹陰
'DateTime:2005-05-18
'Description:更改LISTVIEW的背景色
Dim i As Integer
Lv.ColumnHeaders.Clear
Lv.ListItems.Clear
Lv.ColumnHeaders.Add , "a", "test1", 100
Lv.ListItems.Add , "a1", "123" '取得行寬
picBg.BackColor = Lv.BackColor
Lv.Parent.ScaleMode = vbTwips
picBg.ScaleMode = vbTwips
picBg.BorderStyle = vbBSNone
picBg.AutoRedraw = True
picBg.Visible = False
picBg.Width = Screen.Width '因為我的LISTVIEW會自動調整大小的,所以直接用屏幕的寬度
picBg.Height = Lv.ListItems(1).Height * LvCount '取得要添充的高度
picBg.ScaleHeight = LvCount
picBg.ScaleWidth = 1
picBg.DrawWidth = 1
'-----------------------------
'畫出每行LISTVIEW的顏色
'------------------------------
For i = 1 To LvCount
If i / 2 = Int(i / 2) Then
picBg.Line (0, i - 1)-(1, i), &HC0FFFF, BF
Else
picBg.Line (0, i - 1)-(1, i), 16777152, BF
End If
Next
Lv.Picture = picBg.Image
Lv.ColumnHeaders.Clear
Lv.ListItems.Clear
End Sub