Como pintar linhas em um control ListBox? (VB.NET 2010)
Primeiro temos que definir a propriedade DrawMode para
DrawMode.OwnerDrawFixed, para que seja disparado o evento DrawItem.
E no evento escrevemos:
Vou chamar ao control ListBox de Lista
Private Sub
Lista_DrawItem(sender
As Object, e As
System.Windows.Forms.DrawItemEventArgs)
Handles
Lista.DrawItem
Dim cor As Brush
= Brushes.Black
If e.Index = 5
Then 'Por
exemplo colorir
a linha 5 de uma
cor diferente.
cor = Brushes.Blue
End If
e.DrawBackground()
Dim mybrush As Brush =
Brushes.Beige
e.Graphics.FillRectangle(mybrush,
e.Bounds)
If (e.Index > -1) Then
e.Graphics.DrawString(Lista.Items(e.Index).ToString,
e.Font, cor, e.Bounds)
End If
e.DrawFocusRectangle()
End Sub
|