【发布时间】:2016-08-30 13:16:49
【问题描述】:
我的问题如下:
我有一个包含 aRGB 代码(从 excel 文件中提取)的组合框,如下所示:
255, 149, 55, 39
255, 0, 176, 80
255, 0, 112, 192
...
我的目标是显示颜色列表而不是它们的 rgb 代码。 所以,我尝试这样做,但没有成功:
Private Sub CB_Color_DrawItem(ByVal sender As System.Object, ByVal e As DrawItemEventArgs) Handles CB_Color.DrawItem
If e.Index = -1 Then
Exit Sub
End If
Dim colBrush As Brush = New SolidBrush(Color.FromArgb(CB_Color.Items(e.Index)))
'Drawing rectangles for the color values
e.Graphics.DrawRectangle(New Pen(Brushes.Black), e.Bounds.Left + 2,
e.Bounds.Top + 2, 30, e.Bounds.Height - 5)
e.Graphics.FillRectangle(colBrush, e.Bounds.Left + 3, e.Bounds.Top + 3,
29, e.Bounds.Height - 6)
End Sub
这段代码不会改变任何东西。我的组合框列表中仍然有 rbg 代码。谁能告诉我这段代码有什么问题?
【问题讨论】:
-
我假设要绘制的每种颜色都由
Color.FromArgb(CB_Color.Items(e.Index))定义。用户只需从下拉列表中选择一种颜色,我想我可以通过使用所选项目的索引知道他选择了什么。
标签: vb.net colors combobox argb