在VB中任意设置ListView控件的ListItem的背景颜色

 

 

 

 

Private   Sub SetListItemColor() 
If mlvwPlayList.ListItems.Count = 0 Then Exit Sub 
If picBgBox Is Nothing Then Err.Raise vbObjectError + 1001"Object PlayList""Property PictureBox need to be set." 

Dim i As Long, j As Long, BgColor As Long, FontColor As Long 
Dim ScrollHeight As Single 
Dim mItem As ListItem 
mlvwPlayList.Picture 
= LoadPicture() 
mlvwPlayList.Parent.ScaleMode 
= vbTwips 

With picBgBox 
.Picture 
= LoadPicture() 
.Cls 
.BackColor 
= RGB(&HFF, &HFF, &HFF) 
.ScaleMode 
= vbTwips 
'.BorderStyle = vbBSNone 
.AutoRedraw = True 
.Visible 
= False 
.Width 
= 1 
.Height 
= mlvwPlayList.ListItems(1).Height * (mlvwPlayList.ListItems.Count) 
.DrawWidth 
= 1 
End With 

ScrollHeight 
= mlvwPlayList.ListItems(1).Top 
For i = 1 To mlvwPlayList.ListItems.Count 
Set mItem = mlvwPlayList.ListItems(i) 
FontColor 
= clrItemFontColor 
If i Mod 2 = 0 Then 
BgColor 
= clrItemBgColorNormal 
Else 
BgColor 
= clrItemBgColorAlter 
End If 
mItem.ForeColor 
= FontColor 
For j = 1 To mItem.ListSubItems.Count 
mItem.ListSubItems.Item(j).ForeColor 
= FontColor 
Next j 
picBgBox.Line (
0, mItem.Top - ScrollHeight)-(0, mItem.Top - ScrollHeight + mItem.Height), BgColor, BF 
Next 
mlvwPlayList.PictureAlignment 
= lvwTile
mlvwPlayList.Picture 
= picBgBox.Image 
End Sub

對了,以上提到的,mlvwPlayList:mlvwPlayList.PictureAlignment = lvwTile
如果繪製整塊Item背景而不用平鋪的背景,則運行效率十分低!!七百多條數據就很慢了。
所以注意上面:picBgBox.Width = 1 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值