Main FAQ Category: Beginner (39)
Also in: C# (13) General (9) 
How to convert System.Drawing.Color to the HTML color format and back?
Posted: 3-Apr-2008
Updated: 3-Apr-2008
Views: 9610

For some time i have been using my own custom methods for converting System.Drawing.Color to the HTML color format and the opposite: converting HTML color format to System.Drawing.Color type.

Then i bumped into this on MSDN:  System.Drawing.ColorTranslator

This useful .NET class does the color conversions for us:

To convert .NET Color type to HTML color use:

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

To convert HTML Color type to .NET color type:

System.Drawing.Color newColor = System.Drawing.ColorTranslator.FromHtml("#AABBCC");


I just wish i found this earlier and i hope that this FAQ will help other developers...