下面的例子是将listview隔行变色,你可以修改一下 Public Function LvwAltLinesBackground(ListView As ListView, PictureBox As PictureBox, Optional ByVal BackColorFirst As Boolean, Optional ByVal AltLineBackColor As OLE_COLOR = -1) As StdPicture Dim nHeight As Single Dim nScaleWidth As Single Dim nAltLineBackColor As OLE_COLOR
With ListView If .View = lvwReport Then If .ListItems.Count Then .PictureAlignment = lvwTile nHeight = .ListItems(1).Height With PictureBox .Visible = False .Cls If AltLineBackColor = -1 Then nAltLineBackColor = .BackColor Else nAltLineBackColor = AltLineBackColor End If .BackColor = ListView.BackColor .BorderStyle = 0 .Height = nHeight * 2 .Width = 10 * Screen.TwipsPerPixelX nScaleWidth = .ScaleWidth .AutoRedraw = True If BackColorFirst Then PictureBox.Line (0, nHeight)-Step(nScaleWidth, nHeight), nAltLineBackColor, BF Else PictureBox.Line (0, 0)-Step(nScaleWidth, nHeight - Screen.TwipsPerPixelY), nAltLineBackColor, BF End If Set ListView.Picture = Nothing Set ListView.Picture = .Image Set LvwAltLinesBackground = .Image .AutoRedraw = False If AltLineBackColor = -1 Then .BackColor = nAltLineBackColor End If End With .Refresh Exit Function End If End If Set .Picture = Nothing End With End Function使用 Private Sub zRefresh() LvwAltLinesBackground lvw, picAltLinesBackground, CBool(chkBackColorFirst.Value) End Sub
Public Function LvwAltLinesBackground(ListView As ListView, PictureBox As PictureBox, Optional ByVal BackColorFirst As Boolean, Optional ByVal AltLineBackColor As OLE_COLOR = -1) As StdPicture
Dim nHeight As Single
Dim nScaleWidth As Single
Dim nAltLineBackColor As OLE_COLOR
With ListView
If .View = lvwReport Then
If .ListItems.Count Then
.PictureAlignment = lvwTile
nHeight = .ListItems(1).Height
With PictureBox
.Visible = False
.Cls
If AltLineBackColor = -1 Then
nAltLineBackColor = .BackColor
Else
nAltLineBackColor = AltLineBackColor
End If
.BackColor = ListView.BackColor
.BorderStyle = 0
.Height = nHeight * 2
.Width = 10 * Screen.TwipsPerPixelX
nScaleWidth = .ScaleWidth
.AutoRedraw = True
If BackColorFirst Then
PictureBox.Line (0, nHeight)-Step(nScaleWidth, nHeight), nAltLineBackColor, BF
Else
PictureBox.Line (0, 0)-Step(nScaleWidth, nHeight - Screen.TwipsPerPixelY), nAltLineBackColor, BF
End If
Set ListView.Picture = Nothing
Set ListView.Picture = .Image
Set LvwAltLinesBackground = .Image
.AutoRedraw = False
If AltLineBackColor = -1 Then
.BackColor = nAltLineBackColor
End If
End With
.Refresh
Exit Function
End If
End If
Set .Picture = Nothing
End With
End Function使用
Private Sub zRefresh()
LvwAltLinesBackground lvw, picAltLinesBackground, CBool(chkBackColorFirst.Value)
End Sub