Thursday, December 27, 2007

Convert HTML color to System.Drawing.Color

It's very simple to convert a HTML color (Hexadecimal color) to System.Drawing.Color.

Just ask the System.Drawing.ColorTranslator class to do so.

Color myColor = System.Drawing.ColorTranslator.FromHtml("#660000");

Remember to include the leading '#' sign.


You may also pass in color names instead of the hexadecimal color.


 


Same, if you want to convert the System.Drawing.Color to hexadecimal string.


string htmlColor = System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.Navy);

No comments:

Post a Comment