eelou
asked on
How to translate string color name to hexadecimil value
asp.net 2.0, c#.
I am doing a survey on line. I have a drop down list of colors, and I allow an 'other' string value text box where they can enter in the string name of a color. For those colors in the drop down list, I will already have the hexadecimal values in the code. When the user enters in a string value for a different color, I want to be able to translate that string to a hexadecimal value that I can then use in a Google bar chart, to actually change the color of each bar in the chart.
I guess I could take all the values in this link...http://www.w3schools.com/css/css_colornames.asp, and put key them into a table in my database, and then do a look-up on that table, but are there other ways to do this? Can I do a call to anything anywhere that would get the hexadecimal value that I would need, or what?
I am doing a survey on line. I have a drop down list of colors, and I allow an 'other' string value text box where they can enter in the string name of a color. For those colors in the drop down list, I will already have the hexadecimal values in the code. When the user enters in a string value for a different color, I want to be able to translate that string to a hexadecimal value that I can then use in a Google bar chart, to actually change the color of each bar in the chart.
I guess I could take all the values in this link...http://www.w3schools.com/css/css_colornames.asp, and put key them into a table in my database, and then do a look-up on that table, but are there other ways to do this? Can I do a call to anything anywhere that would get the hexadecimal value that I would need, or what?
Just forgot, if you don't have already, add a reference to System.Drawing.dll
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In case you also want Alpha component in the color
Color color = Color.FromName("Red");
string hexColorValue = string.Format("#{0:X2}{1:X 2}{2:X2}{3 :X2}", color.A, color.R, color.G, color.B);
Thx!
Swaps...
Color color = Color.FromName("Red");
string hexColorValue = string.Format("#{0:X2}{1:X
Thx!
Swaps...
ASKER
I made a mistake, Google charts is looking for "RRGGBB format hexadecimal number"...I forgot to include the "RRGGBB" format.
ASKER
I got some help elsewhere. The answer is that I just needed to remove the '#' from the string.format
ASKER
It would have been an "A", but no one took the time to answer that one further additional question
string hexcolor = System.Drawing.ColorTransl