1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
Public Class LBExemple
Inherits ListBox
' On masque la propriété afin qu'elle ne soit pas modifiable
Public Shadows ReadOnly Property DrawMode() As Windows.Forms.DrawMode
Get
Return MyBase.DrawMode
End Get
End Property
Public Sub New()
MyBase.DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
End Sub
Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
If e.Index < 0 Or Me.DesignMode Then Exit Sub
'
' Couleur de fond :
' si commence par A --> Rouge
' sinon --> on laisse faire
'
Dim strText As String = Me.GetItemText(Me.Items(e.Index))
If strText.StartsWith("A") Then
Dim backbrush As New _
System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, _
Color.Red, _
Color.Fuchsia, _
System.Drawing.Drawing2D.LinearGradientMode.Horizontal)
e.Graphics.FillRectangle(backbrush, e.Bounds)
Else
' On dessine le backGround standard
e.DrawBackground()
End If
e.Graphics.DrawString(strText, Me.Font, System.Drawing.Brushes.Black, e.Bounds)
' Dessin du Focus de l'item si besoin
e.DrawFocusRectangle()
End Sub
End Class |
Partager