David asked a Question in C# Windows

How to convert System.Color to HTML color (hex)?

I’m working on an application that requires converting the back color of the panel to HTML color that can be used as a div background color. Please help.

Updated February 16, 2012

admin answered

Use ColorTranslator. It’s available in the namespace System.Drawing.

Example Usage:

ColorTranslator.ToHtml(panel.BackColor);

The ToHtml function retus the html color in a string format including the #. Example: #FFC0C0.