Tuesday, February 13, 2007

Convert System.Drawing.Color to HTML (#xxxxxx) representation


private string getHexColor(Color cl)
{
string clR;
string clG;
string clB;
if (cl.R == 0) clR = "00"; else clR = cl.R.ToString("x");
if (cl.G == 0) clG = "00"; else clG = cl.G.ToString("x");
if (cl.B == 0) clB = "00"; else clB = cl.B.ToString("x");
return "#" + clR + clG + clB;
}

No comments: