Color.DarkMagenta to #hexcolor

  • Thread starter Thread starter Ron Vecchi
  • Start date Start date
R

Ron Vecchi

I have a color System.Drawing.Color.DarkMagenta
I would like to output it to the browser as its hex color(not sure what it
is) #993484

This seems like it should work but it isn't.
 
Use function
Function convertToHexColor(ByVal c As Color) As String
Return "#" + c.ToArgb().ToString("x").Substring(2)
End Function

HTH
-Sushila
 
I think if you created the Color from a KnownColor, it will always return
you the literal. But it's easy enough to produce the results you want

(sorry, it's VB);

Dim c As System.Drawing.Color = System.Drawing.Color.DarkMagenta
Dim HtmlColor As String = "#"
HtmlColor &= Right("00" & Hex(c.R), 2)
HtmlColor &= Right("00" & Hex(c.G), 2)
HtmlColor &= Right("00" & Hex(c.B), 2)
 
Back
Top