Friday, 19 October 2007

c# Color to HTML/HEX and HEX to C# using ColorTranslator

Often we come across situations to convert html color to appropriate Color Object.

Here is the code to achieve it.

using System.Drawing;

Color colorObj = ColorTranslator.FromHtml("#8b4513");

String htmlColor= System.Drawing.ColorTranslator.ToHtml(colorObj );