Results 1 to 5 of 5

Thread: [2.0] Enumerate the KnownColors

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    Question [2.0] Enumerate the KnownColors

    How can you enumerate an enum?

    Ex:

    The KnownColor enum is full of known color names like White, Black, Green, Red, Gainsboro, etc. I think it includes Web colors as well as System Colors but that's fine.

    What I want to do is give the user an option to pick a Web Color like the Visual Studio Color Selector. I've tried the ColorDialog but it only represents RGB colors.

    The next problem is I'm setting the background color of a label to the color the user picked lblColor.BackColor =
    but there's no way I know of to convert from a KnowColor to Color.

    A cast won't work:
    Code:
    lblColor.BackColor = (Color)KnownColor.Gainsboro;
    [edit]
    I was able to get the BackColor from a KnownColor:
    Code:
    lblColor.BackColor = Color.FromKnownColor(KnownColor.Gainsboro);
    Now I see that the Color enum also contains the members out of KnowColor also.

    But I still don't have a clue how to create a dialog like the VS color picker in the attachment.
    Attached Images Attached Images  
    Last edited by wey97; Oct 23rd, 2006 at 08:49 AM.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: [2.0] Enumerate the KnownColors

    This iterates through KnownColor enum.
    VB Code:
    1. foreach (string colr in Enum.GetNames(typeof(System.Drawing.KnownColor)))
    2.             {
    3.                 MessageBox.Show(colr);
    4.             }

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    Re: [2.0] Enumerate the KnownColors

    Quote Originally Posted by Pirate
    This iterates through KnownColor enum.
    VB Code:
    1. foreach (string colr in Enum.GetNames(typeof(System.Drawing.KnownColor)))
    2.             {
    3.                 MessageBox.Show(colr);
    4.             }
    Great, I just populated a ListBox with the values and when the user changes the selection, the background color changes with Color.FromName(...)

    Now I'm going to have to make the UI a little more advanced. What the user would like is a popup control like the one in the picture I attached from the VS UI but only allow selection from Web Colors. Also, the user would like the grouping shown. Ex: The VS color picker groups similar hues with different shading like Gray, Silver, Gainsboro, etc.

    Is there a way to instantiate the Visual Studio Color Picker at run-time?

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: [2.0] Enumerate the KnownColors


  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    Re: [2.0] Enumerate the KnownColors

    Quote Originally Posted by Pirate
    That may be useful. The only problem I see with it is the alphabetical versus grouping ordering of the list of colors.

    I found this article and source code written in VB so I may try and convert it:
    http://www.vbinfozine.com/a_colorpicker.shtml

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