In C# , How can i create a System.Drawing.Color object using a hex value?

Shyju picture Shyju · Nov 19, 2009 · Viewed 17.2k times · Source

In C# , How can i create a System.Drawing.Color object using a value like this #FFFFF,#FGFG01 etc...

Answer

djdd87 picture djdd87 · Nov 19, 2009
string hexValue = "#000000"; // You do need the hash
Color colour = System.Drawing.ColorTranslator.FromHtml(hexValue); // Yippee

Edit: You do actually need the hash, or the alpha value won't be taken into account. Woops!