Color.DarkMagenta to #hexcolor

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.
 
S

Sonali.NET[MVP]

Use function
Function convertToHexColor(ByVal c As Color) As String
Return "#" + c.ToArgb().ToString("x").Substring(2)
End Function

HTH
-Sushila
 
R

Rob Mayo

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top