How to convert System.Drawing.Color to the HTML color format and back?
Copyright © 2007-2012 www.AspDotNetFaq.com
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...
Copyright © 2007-2012 www.AspDotNetFaq.com