If you are working on some Web-related App then you sooner or later will need to convert a System.Drawing.Color structure to its Html format. Below are three overloaded functions.
/// <summary>
/// Convert System.Drawing.Color struct to a Html color representation
/// </summary>
/// <param name="color">System.Drawing.Color struct to convert from</param>
/// <returns>Html color format as a string</returns>
public string ToHtmlColor(Color color)
{
return "#" + color.ToArgb().ToString("x").Substring(2);
}
/// <summary>
/// Convert Red, Green and Blue components to a Html color representation
/// </summary>
/// <param name="r">The Red component value</param>
/// <param name="g">The Green component value</param>
/// <param name="b">The Blue component value</param>
/// <returns>Html color format as a string</returns>
public string ToHtmlColor(int r, int g, int b)
{
Color color = System.Drawing.Color.FromArgb(r, g, b);
return "#" + color.ToArgb().ToString("x").Substring(2);
}
/// <summary>
/// Convert ARGB color to a Html color representation
/// </summary>
/// <param name="argb">ARGB color value</param>
/// <returns>Html color format as a string</returns>
public string ToHtmlColor(int argb)
{
Color color = System.Drawing.Color.FromArgb(argb);
return "#" + color.ToArgb().ToString("x").Substring(2);
}
df0f5d73-a84d-42f7-b358-6652bc51dd2e|0|.0|96d5b379-7e1d-4dac-a6ba-1e50db561b04