I need to draw each item in a listbox based on the text the items that is about to be added or the text it contains. Then I need to place an icon at the beginning of the listbox, with two other colors and icons depending on words I specify, e.g,
If the item contains error text, place an error(16x16px) icon at the beginning and the draw the background in light red and the text in bold dark red.
If it contains an ready or starting text, then use light orange background and dark bold blue font text.
- If it contains an ok or success text, then use light green background and dark bold green font text.
How can I do this?
EDIT
Here is what i already have, but this code seem to refresh endless. where i need to choose color is the the value of e.index. Can i change the e.index to somthinf like e.stringvalue?
Private Sub lsbLog_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles lsbLog.DrawItem
'//Draw the background of the ListBox control for each item.
'// Create a new Brush and initialize to a Black colored brush
'// by default.
e.DrawBackground()
Dim mybrush = Brushes.Black
'// Determine the color of the brush to draw each item based on
'//the index of the item to draw.
Select Case e.Index
Case 0
mybrush = Brushes.Red
Case 1
mybrush = Brushes.Blue
Case 2
mybrush = Brushes.Green
End Select
'//
'// Draw the current item text based on the current
'// Font and the custom brush settings.
'//
e.Graphics.DrawString(lsbLog.Items(e.Index).ToString(), _
e.Font, mybrush, e.Bounds, StringFormat.GenericDefault)
'//
'// If the ListBox has focus, draw a focus rectangle
'// around the selected item.
'//
e.DrawFocusRectangle()
lsbLog.Refresh()
End Sub