Colors

  • Thread starter Thread starter Paul Smith
  • Start date Start date
P

Paul Smith

I have a button on my web page the backcolor of which I want to change:

btnSample.backcolor = ????????

I want the color to be Gainsboro

However I enter Gainsboro or color.Gainsboro I have the blue wavy line
indicating an error.

Help!
 
color.fromArgb(rr, gg, bb)

where rr, gg, bb are the red, green and blue values that should be mixed to
produce the color you desire.

Microsoft can supply the color class with every color under the sun.
They've provided a good base of colors, but for custom colors, you'll need
to supply the ingredients yourself.
 
When I manually look at the properties of a web control and check it's
backcolor, I see that the color 'Gainsboro' has been selected from the web
color palette. Is it true that in code you cannot change a control's
backcolor to another color from the web palette?

I am a novice programmer, but this seems very strange that you need to
reference code color changes using RGB references, when manually you can
using defined named colors. If this is the case where do you get the RGB
values for each names colour?

PWS
 
While the Properties window does show Gainsboro in the list, remember that
the values you select in the Properties window for web forms controls must
be able to be expressed (or better yet, rendered) to the client (browser) as
something the browser will understand. This is why a Web Forms control
might start out as: <ASP:Button>, but it winds up in the client as <INPUT
TYPE="Submit">. The same is true with property values. The only way to
specify a background color for an HTML control is via Cascading Style Sheets
and the STYLE attribute of the <INPUT> tag.

Now, here's the important part: in CSS, Gainsboro is a valid value for the
"background-color:" style sheet property, BUT there are 2 additional things
to consider...

1. Gainsboro is just a name that your video card must be able to present to
you. Not everyone has the same video card that you have and it is quite
possible that many people's systems will have no idea what Gainsboro is.

2. Even though on your system Gainsboro is a known color and even though
the Cascading Style Sheet language accepts Gainsboro as a value for the
"background-color:" style property, when you are working in .NET code, you
are not working in the Cascading Style Sheet language. You are working in a
different language that will be processed by a web server and the .NET
Framework, not a client browser and a video card. Because of this, you must
use the Color class. Microsoft certainly can't create constant values in
the color class for every color there is, so they created constants exposed
as properties for quite a few common colors. For all other colors, they
gave us the "FromARGB" method to "mix" up a color as we see fit.

To get the RGB of virtually any named color, a simple Google search on:
"gainsboro rgb" returns as the very first result, that 220, 220, 220 is the
RGB for Gainsboro.


-Scott
 
Scott,

Thank you for taking the time to give such a detailed explanation, I do
appreciate, and now understand, the issue.

PWS
 
No problem. Good luck.


Paul Smith said:
Scott,

Thank you for taking the time to give such a detailed explanation, I do
appreciate, and now understand, the issue.

PWS
 

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

Back
Top