locked
How to get all system color names and fill in a DropDownListBox RRS feed

  • Question

  • User1040369262 posted

    I know I can use the following code get pre-defined color name one by one, how can I get all system color names? I can't find a system color name collection

    System.Drawing.Color.Red
    System.Drawing.Color.LightSalmon

     

    Friday, April 17, 2009 7:51 PM

Answers

  • User187056398 posted

    Here's how to get the names and colors (you can fill the dropdownlistbox)

     

            System.Drawing.Color MyColor;
            foreach (string ColorName in Enum.GetNames(typeof(System.Drawing.KnownColor)))
            {
                Response.Write(ColorName + "<br />");
                MyColor = System.Drawing.Color.FromName(ColorName);
            }   
    
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 17, 2009 9:37 PM
  • User187056398 posted

    Yeah, the list includes the "System Colors" (ie the color of a ButtonFace, MenuBar).  These are the colors that the user can change from the control panel.

    Here's a version that filters out the system colors:

        protected void Button1_Click(object sender, EventArgs e)
        {
            System.Drawing.Color MyColor;
            foreach (string ColorName in Enum.GetNames(typeof(System.Drawing.KnownColor)))
            {          
                MyColor = System.Drawing.Color.FromName(ColorName);
                if (MyColor.IsSystemColor == true)
                    continue;
                Response.Write(ColorName + "<br />");
            }            
        }
    
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 20, 2009 9:20 AM

All replies

  • User187056398 posted

    Here's how to get the names and colors (you can fill the dropdownlistbox)

     

            System.Drawing.Color MyColor;
            foreach (string ColorName in Enum.GetNames(typeof(System.Drawing.KnownColor)))
            {
                Response.Write(ColorName + "<br />");
                MyColor = System.Drawing.Color.FromName(ColorName);
            }   
    
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 17, 2009 9:37 PM
  • User-319574463 posted

     Looks an interesting way to get a colout list and tried

            this.GridColour.DataSource = Enum.GetNames(typeof(System.Drawing.KnownColor));
            this.GridColour.DataBind();

    where (absolute size put in to restrict column width)

             <asp:GridView ID="GridColour" runat="server" Width="200px">
            </asp:GridView>

    and gave the following list - manifestly not all are colours!

     

    Item
    ActiveBorder
    ActiveCaption
    ActiveCaptionText
    AppWorkspace
    Control
    ControlDark
    ControlDarkDark
    ControlLight
    ControlLightLight
    ControlText
    Desktop
    GrayText
    Highlight
    HighlightText
    HotTrack
    InactiveBorder
    InactiveCaption
    InactiveCaptionText
    Info
    InfoText
    Menu
    MenuText
    ScrollBar
    Window
    WindowFrame
    WindowText
    Transparent
    AliceBlue
    AntiqueWhite
    Aqua
    Aquamarine
    Azure
    Beige
    Bisque
    Black
    BlanchedAlmond
    Blue
    BlueViolet
    Brown
    BurlyWood
    CadetBlue
    Chartreuse
    Chocolate
    Coral
    CornflowerBlue
    Cornsilk
    Crimson
    Cyan
    DarkBlue
    DarkCyan
    DarkGoldenrod
    DarkGray
    DarkGreen
    DarkKhaki
    DarkMagenta
    DarkOliveGreen
    DarkOrange
    DarkOrchid
    DarkRed
    DarkSalmon
    DarkSeaGreen
    DarkSlateBlue
    DarkSlateGray
    DarkTurquoise
    DarkViolet
    DeepPink
    DeepSkyBlue
    DimGray
    DodgerBlue
    Firebrick
    FloralWhite
    ForestGreen
    Fuchsia
    Gainsboro
    GhostWhite
    Gold
    Goldenrod
    Gray
    Green
    GreenYellow
    Honeydew
    HotPink
    IndianRed
    Indigo
    Ivory
    Khaki
    Lavender
    LavenderBlush
    LawnGreen
    LemonChiffon
    LightBlue
    LightCoral
    LightCyan
    LightGoldenrodYellow
    LightGray
    LightGreen
    LightPink
    LightSalmon
    LightSeaGreen
    LightSkyBlue
    LightSlateGray
    LightSteelBlue
    LightYellow
    Lime
    LimeGreen
    Linen
    Magenta
    Maroon
    MediumAquamarine
    MediumBlue
    MediumOrchid
    MediumPurple
    MediumSeaGreen
    MediumSlateBlue
    MediumSpringGreen
    MediumTurquoise
    MediumVioletRed
    MidnightBlue
    MintCream
    MistyRose
    Moccasin
    NavajoWhite
    Navy
    OldLace
    Olive
    OliveDrab
    Orange
    OrangeRed
    Orchid
    PaleGoldenrod
    PaleGreen
    PaleTurquoise
    PaleVioletRed
    PapayaWhip
    PeachPuff
    Peru
    Pink
    Plum
    PowderBlue
    Purple
    Red
    RosyBrown
    RoyalBlue
    SaddleBrown
    Salmon
    SandyBrown
    SeaGreen
    SeaShell
    Sienna
    Silver
    SkyBlue
    SlateBlue
    SlateGray
    Snow
    SpringGreen
    SteelBlue
    Tan
    Teal
    Thistle
    Tomato
    Turquoise
    Violet
    Wheat
    White
    WhiteSmoke
    Yellow
    YellowGreen
    ButtonFace
    ButtonHighlight
    ButtonShadow
    GradientActiveCaption
    GradientInactiveCaption
    MenuBar
    MenuHighlight

     

    Monday, April 20, 2009 5:37 AM
  • User187056398 posted

    Yeah, the list includes the "System Colors" (ie the color of a ButtonFace, MenuBar).  These are the colors that the user can change from the control panel.

    Here's a version that filters out the system colors:

        protected void Button1_Click(object sender, EventArgs e)
        {
            System.Drawing.Color MyColor;
            foreach (string ColorName in Enum.GetNames(typeof(System.Drawing.KnownColor)))
            {          
                MyColor = System.Drawing.Color.FromName(ColorName);
                if (MyColor.IsSystemColor == true)
                    continue;
                Response.Write(ColorName + "<br />");
            }            
        }
    
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 20, 2009 9:20 AM