我需要根据要添加的项目的文本或其包含的文本在列表框中绘制每个项目。然后我需要在列表框的开头放置一个图标,根据我指定的单词使用另外两种颜色和图标,例如,
如果项目包含错误文本,请在开头放置一个错误(16x16px)图标,并以浅红色绘制背景,以深红色粗体绘制文本。
如果它包含准备好的或开始的文本,则使用浅橙色背景和深蓝色粗体文本。
- 如果它包含 ok 或 success 文本,则使用浅绿色背景和深绿色粗体文本。
我怎样才能做到这一点?
编辑
这是我已经拥有的,但这段代码似乎会不断刷新。我需要选择颜色的地方是 e.index 的值。我可以将 e.index 更改为像 e.stringvalue 这样的 somthinf 吗?
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