RGB color in C# question

  • Thread starter Thread starter Adrian
  • Start date Start date
A

Adrian

Coding a website, one can create RGB colors with three pairs of two-digit
hexadecimal values.
How can one do that in C#?

Many thanks.
 
System.Drawing.Color c = System.Drawing.Color.FromArgb( /* R */ 0xFF, /* G
*/ 0xFF, /* B */ 0xFF);

You can convert a HTML style color string to System.Drawing.Color like this:
System.Drawing.Color c = System.Drawing.ColorTranslator.FromHtml("#FFFFFF");
 
Adrian,

Yes, you can, but the thing is, what are you trying to do? Do you want
a Color structure, or do you want a string?

If you want a color structure, then you could convert each string into
an int (using an overload of the static Parse method on the Int32 structure)
and then pass those into the static FromArgb method of the Color structure.

Hope this helps.
 
Nicholas Paldino said:
Adrian,

Yes, you can, but the thing is, what are you trying to do?

I want to make a little program for myself to help me get colors right
when I am designing a website. Put the R, the G, and the B on slides
and see what happens to the color. Display the value as composed.

Actually, I believe Denis, who also responded, has answered my question
rather well.

However, thank you very much, Nicholas.
 
Dennis Myrén said:
System.Drawing.Color c = System.Drawing.Color.FromArgb( /* R */ 0xFF, /* G
*/ 0xFF, /* B */ 0xFF);

You can convert a HTML style color string to System.Drawing.Color like this:
System.Drawing.Color c = System.Drawing.ColorTranslator.FromHtml("#FFFFFF");

Thank you very much. This is the sort of thing I was looking for.
Regards,
Adrian.
 
Back
Top