By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,421 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Color

P: n/a
Hello,

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

Thanks,
Miguel

May 29 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
string htmlColour = "#FFFFFF";
Color transColor = System.Drawing.ColorTranslator.FromHtml(htmlColour );

Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
"shapper" <md*****@gmail.comwrote in message
news:11**********************@h2g2000hsg.googlegro ups.com...
Hello,

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

Thanks,
Miguel

May 29 '07 #2

P: n/a
"shapper" <md*****@gmail.comwrote in message
news:11**********************@h2g2000hsg.googlegro ups.com...
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...?
--
http://www.markrae.net

May 29 '07 #3

P: n/a
On May 29, 11:18 pm, "Mark Rae" <m...@markNOSPAMrae.netwrote:
"shapper" <mdmo...@gmail.comwrote in message

news:11**********************@h2g2000hsg.googlegro ups.com...
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...?

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

May 29 '07 #4

P: n/a
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

"shapper" <md*****@gmail.comwrote in message
news:11**********************@u30g2000hsc.googlegr oups.com...
On May 29, 11:18 pm, "Mark Rae" <m...@markNOSPAMrae.netwrote:
>"shapper" <mdmo...@gmail.comwrote in message

news:11**********************@h2g2000hsg.googlegr oups.com...
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...?

--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
May 29 '07 #5

P: n/a
This function should do the trick:

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

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net
"shapper" <md*****@gmail.comwrote in message
news:11**********************@h2g2000hsg.googlegro ups.com...
Hello,

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

Thanks,
Miguel
May 30 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.