If you wanted to give a color preview for your color selection process, you could use an extended combobox...
Code:Public Class colorComboBox Inherits ComboBox Public Sub New() Me.DropDownStyle = ComboBoxStyle.DropDownList Me.DrawMode = Windows.Forms.DrawMode.OwnerDrawVariable MyBase.Items.Clear() MyBase.Items.AddRange([Enum].GetNames(GetType(KnownColor)).OrderBy(Function(n) Color.FromName(n).GetHue).ToArray) End Sub Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs) Dim c As Color = Color.Empty If e.Index <> -1 Then c = Color.FromName(MyBase.Items(e.Index).ToString) End If If (e.State And DrawItemState.ComboBoxEdit) = DrawItemState.ComboBoxEdit Then ' Draw the contents of the edit area of the combo box. e.Graphics.FillRectangle(New SolidBrush(c), New Rectangle(4, e.Bounds.Top + 1, 16, 12)) e.Graphics.DrawRectangle(Pens.Black, New Rectangle(4, e.Bounds.Top + 1, 16, 12)) e.Graphics.DrawString(If(c.Name = "0", "Empty", c.Name), Me.Font, Brushes.Black, 22, e.Bounds.Top + 1) Else ' Draw the contents of an item in the drop down list. e.Graphics.FillRectangle(New SolidBrush(c), New Rectangle(2, e.Bounds.Top + 2, 16, 12)) e.Graphics.DrawRectangle(Pens.Black, New Rectangle(2, e.Bounds.Top + 2, 16, 12)) e.Graphics.DrawString(c.Name, Me.Font, Brushes.Black, 20, e.Bounds.Top + 2) ' Draw the focus rectangle. e.DrawFocusRectangle() End If MyBase.OnDrawItem(e) End Sub Public Function getSelectedColor() As Color If MyBase.SelectedIndex > -1 Then Return Color.FromName(MyBase.Text) Else Return Color.Transparent End If End Function End Class![]()




Reply With Quote