Using hexadecimal color code in System.Drawing.Color
Asked Answered
F

4

13

Is there a way to specify the hexadecimal code(something like #E9E9E9) while setting the color of a datagrid instead of using the below code.

dg.BackColor = System.Drawing.Color.LightGray
Fairminded answered 16/2, 2011 at 8:24 Comment(2)
Please mark the correct answer to Answer, so that any other persons can help find answer to this question easily.Uninterested
Thank you. How do I make the forecolor font bold in this same context?Fairminded
Z
26
dg.BackColor =  System.Drawing.ColorTranslator.FromHtml("#E9E9E9");
Zackaryzacks answered 16/2, 2011 at 8:29 Comment(4)
Also take a look at the other functions from ColorTranslator to translate Ole colors or doing the transform vice versa (from Color to html string).Rotatory
You should really take a look into the code of FromHtml with reflector. I like this special handling of LightGrey ;-)Rotatory
Thanks you all,, how can I make the font bold using System.Drawing.Color for any color?Fairminded
@Pooja, open up a new question for that. :)Zackaryzacks
S
1

try this :

dg.BackColor = Sytem.Drawing.Color.FromArgb(0, 0xE9, 0xE9, 0xE9);

or

string myColor = "#E9E9E9";
dg.BackColor = Sytem.Drawing.Color.FromArgb(int.Parse(myColor.Replace("#", "0x"));
Susannahsusanne answered 16/2, 2011 at 8:28 Comment(0)
B
0

Yes.

Color.FromArgb:

dg.BackColor = Color.FromArgb(0xE9, 0xE9, 0xE9);
Bechler answered 16/2, 2011 at 8:28 Comment(0)
A
0

Close:

Color.FromArgb(0, 0xe9, 0xe9, 0xe9);
Algicide answered 16/2, 2011 at 8:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.