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,
DovbermanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
Color.FromArgb(int red, int green, int blue)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AndyAinscowFreelance programmer / ConsultantCommented:
And
Convert.ToInt16("80", 16);  //where the string part is the hex value
0
Pratima PharandeCommented:
System.Drawing.Color.FromArgb(00,99,33)
0
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

AndyAinscowFreelance programmer / ConsultantCommented:
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));
0
DovbermanAuthor Commented:
Thank you.
0
AndyAinscowFreelance programmer / ConsultantCommented:
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.
0
DovbermanAuthor Commented:
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,
0
AndyAinscowFreelance programmer / ConsultantCommented:
>>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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.