CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Enumerating Colours

    Does anyone know of a cool way to enumerate all of the members of Color?

    So, for example, a routine that would display:

    AntiqueWhite [ ]
    Aqua [ ]
    ...
    YellowGreen [ ]

    Where the contents of the [ ] has a background colour matching the Color member?
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Enumerating Colours

    How about...

    Code:
    foreach ( KnownColor name in Enum.GetValues( typeof( KnownColor ) ) )
    {
        Color c = Color.FromKnownColor( name );
    }
    Last edited by BigEd781; July 17th, 2009 at 01:43 AM.

  3. #3
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: Enumerating Colours

    Yep. That's a bit too cool

    Thanks
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

  4. #4
    Join Date
    Feb 2009
    Location
    Atlanta, GA
    Posts
    17

    Re: Enumerating Colours

    You also have a few more colors defined in the SystemColors for form display colors. I hope that helps.
    Scott Knake
    Custom Software Development
    Apex Software, Inc.

  5. #5
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Enumerating Colours

    You could also use the Enum.GetNames method. You have to remember, with all these types of things ( Enums ), for example, the colours, BorderStyles, StartPosition etc., you have to use the same format to get the containing info

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured