vb.net创建自定义颜色下拉列表

该博客展示了如何在VB.NET中创建一个自定义颜色的下拉列表。通过DrawItem事件处理程序,实现了在列表框中填充颜色并显示对应的文字。同时,当选项被选中时,会在列表项旁边绘制一个指示箭头,并更新背景图片。
摘要由CSDN通过智能技术生成
   Private Sub LB_DtColorsFilter_DrawItem(ByVal sender As Object, ByVal e As DrawItemEventArgs) Handles LB_DtColorsFilter.DrawItem
        If LB_DtColorsFilter.Items.Count = 0 Then Exit Sub


        e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(DtColorsFilter.Rows.Item(e.Index)(1))), e.Bounds)
        '字体格式
        Dim sf As New StringFormat With {
            .Alignment = StringAlignment.Far,
            .LineAlignment = StringAlignment.Center
        }
        Dim textBrush As SolidBrush = New SolidBrush(Color.FromArgb(DtColorsFilter.Rows.Item(e.Index)(6)))
        '文字
        e.Graphics.DrawString(DtColorsFilter.Rows.Item(e.Index)(0), Me.Font, textBrush, e.Bounds, sf)
        If LB_DtColorsFilter.SelectedIndex = e.Index Then
            Dim rect As Rectangle = New Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height - 1)
            e.Graphics.DrawRectangle(New Pen(textBrush), rect)
            sf.Alignment = StringAlignment.Near
            e.Graphics.DrawString(">", Me.Font, textBrush, rect, sf)
            PB_MaterialFactory.BackgroundImage = DtColorsFilter.Rows.Item(e.Index)(4)
        End If
    End Sub
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值