Mewarnai ListView secara belang
Prosedur ini akan mewarnai kontrol ListView secara belang, sehingga mempermudah user untuk membacanya.
Buat sebuah Module baru, lalu tambahkan kode berikut :
Public Sub SetLvwColor(ByVal Lvw As ListView, ByVal Pic As PictureBox, Optional ByVal StartAtOddRow As Boolean = False, Optional ByVal AltBackColor As OLE_COLOR = -1)
On Error GoTo Ero
Dim t As Integer, h As Single, sw As Single
Dim oAltBackColor As OLE_COLOR
If AltBackColor = -1 Then oAltBackColor = Pic.BackColor Else oAltBackColor = AltBackColor
With Lvw
.View = lvwReport
If .ListItems.Count = 0 Then t = .ListItems.Add(, , "temp").Index 'add temp
.PictureAlignment = lvwTile
h = .ListItems(1).Height
With Pic
.Visible = False
.BackColor = Lvw.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), oAltBackColor, BF
End If
Set Lvw.Picture = .Image
.AutoRedraw = False
.BackColor = oAltBackColor
End With
.Refresh
On Error Resume Next
.ListItems.Remove (t) 'remove temp
End With
Exit Sub
Ero:
MsgBox Err.Description, , "ListView BackColor"
End Sub
On Error GoTo Ero
Dim t As Integer, h As Single, sw As Single
Dim oAltBackColor As OLE_COLOR
If AltBackColor = -1 Then oAltBackColor = Pic.BackColor Else oAltBackColor = AltBackColor
With Lvw
.View = lvwReport
If .ListItems.Count = 0 Then t = .ListItems.Add(, , "temp").Index 'add temp
.PictureAlignment = lvwTile
h = .ListItems(1).Height
With Pic
.Visible = False
.BackColor = Lvw.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), oAltBackColor, BF
End If
Set Lvw.Picture = .Image
.AutoRedraw = False
.BackColor = oAltBackColor
End With
.Refresh
On Error Resume Next
.ListItems.Remove (t) 'remove temp
End With
Exit Sub
Ero:
MsgBox Err.Description, , "ListView BackColor"
End Sub
Untuk percobaannya, buat form baru dengan sebuah ListView dan sebuah PictureBox. Setelah itu tambahkan kode berikut di bagian 'Form_Load'.
SetLvwColor ListView1, Picture1
Pewarnaan dapat dirubah dengan mengganti properti 'BackColor' pada kontrol PictureBox.
Label: (Menengah), Kontrol, VB 6.0
0 Komentar:
Posting Komentar
Pengunjung yang baik selalu meninggalkan jejak berupa komentar. :)
Berlangganan Posting Komentar [Atom]
<< Beranda