Search code examples
winformscomboboxcolor-picker

Winforms combobox containing system color names?


What's the easiest way to list system drawing color names in a combobox? (we don't need a full blown color picker or to see the any coloring, just the color names in black and white)


Solution

  • Something like this:

    ComboBox combo = new ComboBox();
    foreach (KnownColor knownColor in Enum.GetValues(typeof(KnownColor)))
    {
        Color color = Color.FromKnownColor(knownColor);
        if (!color.IsSystemColor)
        {
            combo.Items.Add(color);
        }
    }
    

    The !color.IsSystemColor check excludes the "colors" that Windows uses for various UI elements (e.g. Menu, WindowFrame).