Search code examples
c#.netcolorssystem.drawing.color

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


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


Solution

  • 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!