i am adding a color list in a combo box....using the code below.
My question is..
is there a way to sort it the same why the have it listed in the properties window? so the colors are grouped? Thanks!
My question is..
is there a way to sort it the same why the have it listed in the properties window? so the colors are grouped? Thanks!
Code:
'in form load
Dim ColorName As String
For Each ColorName In System.Enum.GetNames(GetType(System.Drawing.KnownColor))
Dim Syscolor As Color = Color.FromName(ColorName)
If Not Syscolor.IsSystemColor Then
cboColor.Items.Add(Color.FromName(ColorName))
End If
Next
'-----
Protected Sub cboColor_MeasureItem(ByVal sender As Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles cboColor.MeasureItem
e.ItemHeight = 40
End Sub
Protected Sub cboColor_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles cboColor.DrawItem
If e.Index < 0 Then
e.DrawBackground()
e.DrawFocusRectangle()
Exit Sub
End If
Dim CurrentColor As Color = CType(cboColor.Items(e.Index), Color)
Dim SizeRect As Rectangle = New Rectangle(2, e.Bounds.Top + 2, 40, e.Bounds.Height - 6)
Dim ComboBrush As Brush
e.DrawBackground()
e.DrawFocusRectangle()
If e.State = Windows.Forms.DrawItemState.Selected Then
ComboBrush = Brushes.White
Else
ComboBrush = Brushes.Black
End If
e.Graphics.DrawRectangle(New Pen(CurrentColor), SizeRect)
e.Graphics.FillRectangle(New SolidBrush(CurrentColor), SizeRect)
e.Graphics.DrawString(CurrentColor.Name, cboColor.Font, ComboBrush, e.Bounds.Height + 20, ((e.Bounds.Height - cboColor.Font.Height) \ 2) + e.Bounds.Top)
End Sub