1 Attachment(s)
[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.
Re: [2.0] Enumerate the KnownColors
This iterates through KnownColor enum.
VB Code:
foreach (string colr in Enum.GetNames(typeof(System.Drawing.KnownColor)))
{
MessageBox.Show(colr);
}
Re: [2.0] Enumerate the KnownColors
Quote:
Originally Posted by Pirate
This iterates through KnownColor enum.
VB Code:
foreach (string colr in Enum.GetNames(typeof(System.Drawing.KnownColor)))
{
MessageBox.Show(colr);
}
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?
Re: [2.0] Enumerate the KnownColors
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