Color

S

shapper

Hello,

How can I convert a variable of type color to a String where the color
is in the format #FFFFFF?

Thanks,
Miguel
 
M

Mark Rae

How can I convert a variable of type color to a String where the color
is in the format #FFFFFF?

Not quite sure what you're looking for here - what are you expecting the
string to contain after the conversion...?
 
S

shapper

Not quite sure what you're looking for here - what are you expecting the
string to contain after the conversion...?

--http://www.markrae.net

I want to use the string #FFFFFF in a style. So i need the color in
that format.
So if color is white I need to get "#FFFFFF"

Thanks,
Miguel
 
P

Papanii

I think this is what you want.

Color color = Color.White;
string hexFormat= string.Format("#{0:X}", color.ToArgb());
Console.WriteLine(hexFormat);

//note: written in C#

--Papanii
 
S

Steve C. Orr [MCSD, MVP, CSM, ASP Insider]

This function should do the trick:

public static string GetRgbHex(Color c)
{
return string.Format("{0:x6}", c.ToArgb() & 0xFFFFFF);
}
 

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,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top