RGB color in C# question

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

Dennis Myrén

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");
 
N

Nicholas Paldino [.NET/C# MVP]

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

Adrian

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

Adrian

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top