Convert Color

SIMIN

Regular
Joined
Mar 10, 2008
Messages
92
Hi,
How can I convert a color in a format like:

Color [A=255, R=255, G=255, B=255]

to a format like:

#ffffff

???
 
string.Format

Ignoring the alpha component:

C#:
string str = string.Format("#{0:x6}", color.ToArgb() & 0x00ffffff);

Or in VB:

Visual Basic:
Dim str As String = String.Format("#{0:x6}", color.ToArgb() And &H00FFFFFF)

Good luck :cool:
 
Well, I think I was unable to clarify myself.
I have a color in HTML format, like #ffffff for example.
I wanna convert it to standard System.Drawing.Color format.
So input is string, but output is NOT, output is RGB color format.
Thanks.
 
Open wide...

I wonder how many other people misinterpreted your post... never mind.

Assuming the string is exactly the format "#ffffff", then this would work:

C#:
color = Color.FromArgb(int.Parse(htmlString.Substring(1), System.Globalization.NumberStyles.HexNumber));

Information on all these types and methods are available in the MSDN help, and in the Object Browser. I suggest you use them.

Good luck :cool:
 
Back
Top