加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

vb.net – 更改列表框上包含drawitem上特定字符串的特定项目的颜

发布时间:2020-12-17 00:08:17 所属栏目:大数据 来源:网络整理
导读:我想更改包含特定字符串的项目的颜色 Private Sub ListBox2_DrawItem(ByVal sender As Object,ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox2.DrawItem e.DrawBackground() If DrawItemState.Selected.ToString.Contains("specific s
我想更改包含特定字符串的项目的颜色
Private Sub ListBox2_DrawItem(ByVal sender As Object,ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox2.DrawItem
    e.DrawBackground()
    If DrawItemState.Selected.ToString.Contains("specific string") Then
        e.Graphics.FillRectangle(Brushes.LightGreen,e.Bounds)
    End If

    e.DrawFocusRectangle()

这是我的代码,但没有工作

好吧,首先你需要将列表框的属性DrawMode设置为“OwnerDrawFixed”而不是Normal.否则你永远不会触发DrawItem事件.完成后,这一切都非常简单.
Private Sub ListBox1_DrawItem(sender As System.Object,e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
    e.DrawBackground()

    If ListBox1.Items(e.Index).ToString() = "herp" Then

        e.Graphics.FillRectangle(Brushes.LightGreen,e.Bounds)
    End If
    e.Graphics.DrawString(ListBox1.Items(e.Index).ToString(),e.Font,Brushes.Black,New System.Drawing.PointF(e.Bounds.X,e.Bounds.Y))
    e.DrawFocusRectangle()
End Sub

如果选择,您将不得不用不同的颜色触摸它.但这应该足以让你继续努力.你很亲密,记住这一点.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读