System.Drawing.Color OrangeColor = System.Drawing.ColorTranslator.FromHtml("#CE56CC");
You can also translate colors without the ColorTranslator class (which may be useful if you are using the Compact Framework).
System.Drawing.Color only supports creating custom colors using it's FromArgb method, which requires base-10 inputs. Therefore, two conversion functions are needed - a conversion from decimal to hexadecimal, and a conversion from a 6 character string to three numeric parts (one each for red, green, and blue).
Source CodeThe first function handles the safe conversion of a hexadecimal (base-16) number to decimal (base-10).
1protected int HexStringToBase10Int(string hex)
2...{
3 int base10value = 0;
4
5 try ...{ base10value = System.Convert.ToInt32(hex, 16); }
6 catch ...{ base10value = 0; }
7
8 return base10value;
9}
The next function breaks the hexadecimal string into parts, removes a leading # (so you can pass it #FF00FF or FF00FF with the same result), and then converts the hexadecimal parts into decimal, and creates a color using the red, green, and blue value integers.
1protected System.Drawing.Color HexStringToColor(string hex)
2...{
3 hex = hex.Replace("#", "");
4
5 if (hex.Length != 6)
6 throw new Exception(hex +
7 " is not a valid 6-place hexadecimal color code.");
8
9 string r, g, b;
10
11 r = hex.Substring(0, 2);
12 g = hex.Substring(2, 2);
13 b = hex.Substring(4, 2);
14
15 return System.Drawing.Color.FromArgb(HexStringToBase10Int(r),
16 HexStringToBase10Int(g),
17 HexStringToBase10Int(b));
18}
from: http://www.akxl.net/labs/articles/converting-a-hexadecimal-color-to-a-system.drawing.color-object/