473,403 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Color

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
5 1510
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
"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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: dan glenn | last post by:
(PHP4.3.4, GD2) How can I save a PNG using GD2 and insure that it saves as a palette-based (8-bit, 256-color) single-color transparancy?? Saving this way, I could be sure that an image loaded from...
6
by: me | last post by:
good day, i found this message: and i want to know more about it too. ========================================== Hey all, example:...
6
by: rzed | last post by:
I'm using PIL to generate some images which may be rotated at the user's option. When they are rotated, the original image is cropped in the new image (which is fine), and the corners are black...
3
by: Richard A. DeVenezia | last post by:
I hope this is the end of my present 'discovery' phase. I've learned alot about JavaScript in a short time and my head hurts. The following is what came out of all my questions and all the...
5
by: Chris Beall | last post by:
I'm displaying an image that is also a link against a black background. In Netscape 7.1, the current background color is displayed as a horizontal bar below the image. This allows :hover effects...
4
by: bart plessers | last post by:
Hello, I am making a website where the user can choose a 'skin'. This works with asp en stylesheets. In the stylesheet, a number of tags are (re)defined. The main idea is to have a limited...
18
by: Jan Tuxen | last post by:
Jakob Nielsen in his most recent Alertbox (http://www.useit.com/alertbox/20040503.html) tells web authors to change the color of visited links. I agree to his purpose: Help users understand...
25
by: Neal | last post by:
According to the CSS lint at http://htmlhelp.org/tools/csscheck/, "The shorthand background property is more widely supported than background-color." Can anyone point me to, or provide, information...
27
by: Kevin Yu | last post by:
When I declare on HTML page <LINK href="mycss.css" type="text/css" rel=stylesheet /> .... <BODY class=myclass> in mycss.css BODY { FONT-WEIGHT: bold; FONT-SIZE: 12px; FONT-FAMILY:...
7
by: Jonathan N. Little | last post by:
When doing a final check on my stylesheets the CSS Validator flag lines like this one as an error: ADDRESS A { color: gold; } Error is: # Line: 31 Context : ADDRESS A Invalid number :...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.