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
vb.net创建自定义颜色下拉列表
最新推荐文章于 2019-05-17 21:58:09 发布
该博客展示了如何在VB.NET中创建一个自定义颜色的下拉列表。通过DrawItem事件处理程序,实现了在列表框中填充颜色并显示对应的文字。同时,当选项被选中时,会在列表项旁边绘制一个指示箭头,并更新背景图片。
摘要由CSDN通过智能技术生成