Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3984122
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:43:53+00:00 2026-05-20T05:43:53+00:00

Hallo everbody, if for example I set the BackColor of a Panel in Winform

  • 0

Hallo everbody,

if for example I set the BackColor of a Panel in Winform using Visual Studio, I can pick up the color from 3 lists:

Custom, Web, System

Is it possible to retreive only the Web colors in my C# code application? They are part of KnownColor but so far I could only find how to eliminate System Control from my list.

I would like to use the web colors because they are sorted in a nice way and I would like to insert them into a self-implemented combobox.

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:43:54+00:00Added an answer on May 20, 2026 at 5:43 am

    Color struct contains all the web colors as constants (system colors are defined as constants in SystemColors class)

    To get a list of these colors just do:

    var webColors = GetConstants(typeof(Color));
    var sysColors = GetConstants(typeof(SystemColors));
    

    having GetConstants defined as follow:

    static List<Color> GetConstants(Type enumType)
    {
        MethodAttributes attributes = MethodAttributes.Static | MethodAttributes.Public;
        PropertyInfo[] properties = enumType.GetProperties();
        List<Color> list = new List<Color>();
        for (int i = 0; i < properties.Length; i++)
        {
            PropertyInfo info = properties[i];
            if (info.PropertyType == typeof(Color))
            {
                MethodInfo getMethod = info.GetGetMethod();
                if ((getMethod != null) && ((getMethod.Attributes & attributes) == attributes))
                {
                    object[] index = null;
                    list.Add((Color)info.GetValue(null, index));
                }
            }
        }
        return list;
    }
    

    EDIT:

    To get colors sorted exactly like in VS do:

    var webColors = GetConstants(typeof(Color));
    var sysColors = GetConstants(typeof(SystemColors));
    
    webColors.Sort(new StandardColorComparer());
    sysColors.Sort(new SystemColorComparer());
    

    with StandardColorComparer and SystemColorComparer defined as follows:

    class StandardColorComparer : IComparer<Color>
    {
        // Methods
        public int Compare(Color color, Color color2)
        {
            if (color.A < color2.A)
            {
                return -1;
            }
            if (color.A > color2.A)
            {
                return 1;
            }
            if (color.GetHue() < color2.GetHue())
            {
                return -1;
            }
            if (color.GetHue() > color2.GetHue())
            {
                return 1;
            }
            if (color.GetSaturation() < color2.GetSaturation())
            {
                return -1;
            }
            if (color.GetSaturation() > color2.GetSaturation())
            {
                return 1;
            }
            if (color.GetBrightness() < color2.GetBrightness())
            {
                return -1;
            }
            if (color.GetBrightness() > color2.GetBrightness())
            {
                return 1;
            }
            return 0;
        }
    }
    
    class SystemColorComparer : IComparer<Color>
    {
        // Methods
        public int Compare(Color color, Color color2)
        {
            return string.Compare(color.Name, color2.Name, false, CultureInfo.InvariantCulture);
        }
    }
    

    N.B. :

    This code has been taken from System.Drawing.Design.ColorEditor through reflector.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hallo all. i want to create a .htaccess file if i type subdomain.domain.com can
Hallo everybody, I'd like to use black color as default text color only in
Hello everybody With EF4, i can map a EDMX function (with update model from
Hello Everybody I want set date in to datepicker from string like above format
Hallo and good sunday to everybody. I need to select N random records from
Hallo, i am using WSS 3.0 and i need to display certain entries of
Hello everybody i have C++ tStringGrid I want to get string from specific cell
Hallo everyone i'm trying to use the initbinder annotations in order to match the
Hallo, Recently I have read a couple of posts on varous sites and blogs
Hallo all. if i have week number 42 and i need to know what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.