Salut,
Il est préférable d'utiliser une listview qui offre bien plus d'options qu'une listbox.
Cependant, il est possible de personnaliser les items d'une ListBox en définissant sa propriété DrawMode comme ceci :
ListBox1.DrawMode = DrawMode.OwnerDrawFixed
et en se servant de son événement DrawItem :
Private Sub ListBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
If e.State = DrawItemState.Selected Then
e.DrawBackground()
e.Graphics.FillRectangle(New SolidBrush(Color.Yellow), e.Bounds)
e.Graphics.DrawString(ListBox1.Items.Item(e.Index), e.Font, New SolidBrush(Color.Red), e.Bounds)
ElseIf e.State = DrawItemState.None Then
e.DrawBackground()
e.Graphics.DrawString(ListBox1.Items.Item(e.Index), e.Font, Brushes.Black, e.Bounds)
End If
e.DrawFocusRectangle()
End Sub
Bonne soirée.
14 févr. 2015 à 09:04