|
楼主 |
发表于 2010-9-22 21:18
|
显示全部楼层
回复 40楼 高度保密 的帖子
LIstview隔行显示不同颜色的核心代码如下:
Private Sub SetListItemColor(lv As ListView, picBg As PictureBox, LvCount As Long, fg As Integer)
'LvCount用于统计当前Listview页面中显示的表格行数,该值根据实际情况来设置
'fg是用来设置Listview中隔行显示不同颜色的风格 fg的取值范围为1-3 为三种不同风格
On Error Resume Next
Dim i As Long, arr1(), arr2()
arr1 = Array(&HFF00&, RGB(254, 200, 100), RGB(227, 241, 226))
arr2 = Array(&HC0FFC0, RGB(254, 209, 199), vbWhite)
If lv.ListItems.Count > LvCount Then
LvCount = lv.ListItems.Count
End If
picBg.BackColor = lv.BackColor
lv.Parent.ScaleMode = vbTwips
picBg.ScaleMode = vbTwips
picBg.BorderStyle = vbBSNone
picBg.AutoRedraw = True
picBg.Visible = False
picBg.Width = Screen.Width
picBg.Height = lv.ListItems(1).Height * LvCount
picBg.ScaleHeight = LvCount
picBg.ScaleWidth = 1
picBg.DrawWidth = 1
'-----------------------------
'custom.such as
'------------------------------
For i = 1 To LvCount
If i Mod 2 = 0 Then
picBg.Line (0, i - 1)-(1, i), arr2(fg - 1), BF
Else
picBg.Line (0, i - 1)-(1, i), arr1(fg - 1), BF
End If
Next
lv.Picture = picBg.Image
Erase arr1
Erase arr2
End Sub |
|