Link to home
Start Free TrialLog in
Avatar of Dovberman
DovbermanFlag for United States of America

asked on

How to set the backcolor of a control


The following statement sets the BackColor to a named color.
celHole2.BackColor = System.Drawing.Color.Green;

How do I set the BackColor to a Hex color? ie. Hex={00,99,33} RGB

celHole2.BackColor = System.Drawing.Color.{00,99,33} RGB;

Thanks,
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And
Convert.ToInt16("80", 16);  //where the string part is the hex value
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Is something not clear?


eg.
this.listBox1.BackColor = Color.FromArgb( Convert.ToInt16("FF", 16), Convert.ToInt16("00", 16), Convert.ToInt16("00", 16));

or this with your colour

this.listBox1.BackColor = Color.FromArgb( Convert.ToInt16("00", 16), Convert.ToInt16("99", 16), Convert.ToInt16("33", 16));
Avatar of Dovberman

ASKER

Thank you.
Don't forget - the comment from pratima_mcs doesn't actually work for what you requested (hex values for the colours).  Try it with another valid hex value
System.Drawing.Color.FromArgb(FF,99,33) and it won't even compile.
I used celHole1.BackColor = System.Drawing.Color.FromArgb(00, 99, 33);

This works.

I did not notice the System.Drawing.Color.FromArgb(FF,99,33) statement from Pratima MCS.

The statement from Pratima MCS that I used successfully was System.Drawing.Color.FromArgb(00, 99, 33);

If I miscalculated the credits, please ask the monitor to make the correction.

Thank you,
>>celHole1.BackColor = System.Drawing.Color.FromArgb(00, 99, 33);

That is NOT using those hex values you specified, they are the int values.  To use those hex values you must convert them to integer values - see my comments.


credits - I'll leave it in your hands if you want to ask a moderator to change things.  I posted my later comment in case you didn't realise the mistake that a hex value of 99 is not the same as an integer value of 99.