我有一个ownerdraw列表框,我正在尝试使用以下内容来更改颜色。
这很好用,除非我退出应用程序时出现错误
InvalidArgument =' -1'的值对于' index'无效。 参数名称:索引在线e.Graphics.DrawString(ListBox1.GetItemText(ListBox1.Items(e.Index)),e.Font,b,e.Bounds)
我怎么能阻止这一点。
Private Sub ListBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
e.DrawBackground()
If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
e.Graphics.FillRectangle(Brushes.Orange, e.Bounds)
End If
Using b As New SolidBrush(e.ForeColor)
e.Graphics.DrawString(ListBox1.GetItemText(ListBox1.Items(e.Index)), e.Font, b, e.Bounds)
End Using
e.DrawFocusRectangle()
End Sub