前端之家收集整理的这篇文章主要介绍了
VB ListView 隔行背景,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Private Sub SetListViewColor(Lv As ListView,pic As PictureBox,LvCount As Long)
Dim i As Integer
pic.BackColor = Lv.BackColor
Lv.Parent.ScaleMode = vbTwips
pic.ScaleMode = vbTwips
pic.BorderStyle = vbBSNone
pic.AutoRedraw = True
pic.Visible = False
pic.Width = Screen.Width '因为我的LISTVIEW会自动调整大小的,所以直接用屏幕的宽度
pic.Height = Lv.ListItems(1).Height * LvCount '取得要添充的高度
pic.ScaleHeight = LvCount
pic.ScaleWidth = 1
pic.DrawWidth = 1
'-----------------------------
'画出每行LISTVIEW的颜色
'------------------------------
For i = 1 To LvCount
If i / 2 = Int(i / 2) Then
pic.Line (0,i - 1)-(1,i),&HC0FFFF,BF
Else
pic.Line (0,16777152,BF
End If
Next
Lv.Picture = pic.Image
End Sub
Private Sub SetListViewColor(Lv As ListView,pic As PictureBox)
Dim h As Single
Dim sw As Single
Dim oAltBackColor As OLE_COLOR
oAltBackColor = pic.BackColor
With Lv
If .View = lvwReport Then
If .ListItems.Count Then
.PictureAlignment = lvwTile
h = .ListItems(1).Height
With pic
.Visible = False
.BackColor = Lv.BackColor
.BorderStyle = 0
.Height = h * 2
.Width = 10 * Screen.TwipsPerPixelX
sw = .ScaleWidth
.AutoRedraw = True
If StartAtOddRow Then
pic.Line (0,0)-Step(sw,h - Screen.TwipsPerPixelY),oAltBackColor,BF
Else
pic.Line (0,h)-Step(sw,h),BF
End If
Set Lv.Picture = .Image
.AutoRedraw = False
.BackColor = oAltBackColor
End With
.Refresh
Exit Sub
End If
End If
Set .Picture = Nothing
End With
End Sub
原文链接:https://www.f2er.com/vb/259115.html