Numeric values of Color.....

  • Thread starter Thread starter Jack Smith
  • Start date Start date
J

Jack Smith

I am using Image button and its property backcolor = DarkGray.

How to find out the numeric value of this color?

Thanks,

Jack
 
I assume by numeric value you mean the RGB values associated with that
color.

The values should then be in the Color.R, Color.G and Color.B byte values.
If you need to convert them to hex you can do something like this:

ImageButton.BackColor.R.ToString("X2");
ImageButton.BackColor.G.ToString("X2");
ImageButton.BackColor.B.ToString("X2");

If you are pulling the color by name you might have to do this:
System.Drawing.Color myColor = System.Drawing.Color.FromName("DarkGray");

Hope that helps,
Kyle
 
The best way is to use the ColorTranslator:

Color c = ColorTranslator.FromHtml("DarkGray");
Response.Write(c.R);
Response.Write(c.G);
Response.Write(c.B);

which is located in System.Drawing (you'll need to reference that dll).

Karl
 
Back
Top