.NETGURU
hexadecimal to color
Messages   Related Types
This message was discovered on ASPFriends.com 'ngfx-drawing' list.


Yannick Smits
How can I convert a hexadecimal colorcode (ie #b5ccff) to a
System.Drawing.Color object (C#)?

Thanks,
Yannick Smits

Reply to this message...
 
    
Minh Truong
[Original message clipped]

Yannick,

Untested, but try:

System.Drawing.Color MyColor =
System.Drawing.ColorTranslator.FromHtml("#b5ccff");

Reply to this message...
 
    
Yannick Smits
I tried both
Color.FromName("#6B696B") and
ColorTranslator.FromHtml("#b5ccff");
but both fail to work. They only work when using a named color like "Red"
not for hexadecimal naming.

Thanks,
Yannick Smits

"André Colbiörnsen" <Click here to reveal e-mail address> wrote in message
news:696486@ngfx-drawing...

Like this (Both VB and C#):

Color.FromName("#6B696B")

Hth

Regards/Halsningar

Andre Colbiornsen
--------------------------------------
Sonnenburg Communications
Bergsgatan 3,
SE-211 54 Malmö
Sweden
Tel.: +46-(0)40-97 78 80
Fax.: +46-(0)40-97 78 80
Mob.: +46-(0)708-97 78 79
Mail: Click here to reveal e-mail address
Web.: www.sonnenburg.se
----------------------------------------
B2B Web Solutions - Specializing in .Net
----------------------------------------

-----Ursprungligt meddelande-----
Från: Yannick Smits [mailto:Click here to reveal e-mail address]
Skickat: den 12 augusti 2002 04:52
Till: ngfx-drawing
Ämne: [ngfx-drawing] hexadecimal to color

How can I convert a hexadecimal colorcode (ie #b5ccff) to a
System.Drawing.Color object (C#)?

Thanks,
Yannick Smits

| [ngfx-drawing] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-drawing.asp = JOIN/QUIT

Reply to this message...
 
    
Alex Dresko
I learned a better way this weekend.

System.Drawing.Color color = new System.Drawing.Color(0xB5CCFF);

Alex Dresko
Three Point Oh!

-----Original Message-----
From: Minh Truong [mailto:Click here to reveal e-mail address]
Sent: Monday, August 12, 2002 12:15 AM
To: ngfx-drawing
Subject: [ngfx-drawing] Re: hexadecimal to color

[Original message clipped]

Yannick,

Untested, but try:

System.Drawing.Color MyColor =
System.Drawing.ColorTranslator.FromHtml("#b5ccff");

| [ngfx-drawing] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-drawing.asp = JOIN/QUIT

Reply to this message...
 
    
Shan Nunez, Eduardo

    True, Color.FromName only works with named colors, but I have used
ColorTranslator.FromHTML frequently in C#
    and it works fine enough, what sort of error do you get when you use
it?
    Anyway, you could try this workaround: convert the html color string
to an hexadecimal value ("#ffffff" -> 0xfffffff).     Then you get its RGB
components (i.e using shifting operators) and create the color    with
Color.FromARGB(int r, int g,=20
    int b).

    Hope this will help.

            Ed.

-----Original Message-----
From: Yannick Smits [mailto:Click here to reveal e-mail address]
Sent: lunes, 12 de agosto de 2002 14:08
To: ngfx-drawing
Subject: [ngfx-drawing] Re: hexadecimal to color

I tried both
Color.FromName("#6B696B") and
ColorTranslator.FromHtml("#b5ccff");
but both fail to work. They only work when using a named color like =
"Red"
not for hexadecimal naming.

Thanks,
Yannick Smits

"Andr=E9 Colbi=F6rnsen" <Click here to reveal e-mail address> wrote in message
news:696486@ngfx-drawing...

Like this (Both VB and C#):

Color.FromName("#6B696B")

Hth

Regards/Halsningar

Andre Colbiornsen
--------------------------------------
Sonnenburg Communications
Bergsgatan 3,
SE-211 54 Malm=F6
Sweden
Tel.: +46-(0)40-97 78 80
Fax.: +46-(0)40-97 78 80
Mob.: +46-(0)708-97 78 79
Mail: Click here to reveal e-mail address
Web.: www.sonnenburg.se
----------------------------------------
B2B Web Solutions - Specializing in .Net
----------------------------------------

-----Ursprungligt meddelande-----
Fr=E5n: Yannick Smits [mailto:Click here to reveal e-mail address]
Skickat: den 12 augusti 2002 04:52
Till: ngfx-drawing
=C4mne: [ngfx-drawing] hexadecimal to color

How can I convert a hexadecimal colorcode (ie #b5ccff) to a
System.Drawing.Color object (C#)?

Thanks,
Yannick Smits

| [ngfx-drawing] member Click here to reveal e-mail address =3D YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-drawing.asp =3D JOIN/QUIT

| [ngfx-drawing] member Click here to reveal e-mail address =3D YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-drawing.asp =3D JOIN/QUIT

Reply to this message...
 
    
Yannick Smits
I found the problem. I was passing the hexvalue through the QueryString and
forgot to UrlEncode it (it doesn't like the sharp sign). Now BOTH methods
are working fine!

Thanks to all,
Yannick Smits

--
Yannick Smits

"Yannick Smits" <Click here to reveal e-mail address> wrote in message
news:696547@ngfx-drawing...
[Original message clipped]

Reply to this message...
 
 
System.Drawing.Color
System.Drawing.ColorTranslator




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification