Colors

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!
 
S

Scott M.

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.
 
P

Paul Smith

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
 
S

Scott M.

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
 
P

Paul Smith

Scott,

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

PWS
 
S

Scott M.

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
 
B

Brendan Green

Excuse me, but I seriously don't think that the type of video card that you
have in your computer has anything to do with this.

The color "Gainsboro" would likely be defined in some web standard. As long
as the browsers *rendering engine* can interpret what Gainsboro should be,
it'll display fine.

The code that you are working on is executed server side. The resultant
output of this execution is valid HTML. The Color struct cotains
definitions for a set number of colors. If you want to use a colour that is
not provided, then you use the RGB representation instead.
 
S

Scott M.

Brendan Green said:
Excuse me, but I seriously don't think that the type of video card that
you have in your computer has anything to do with this.

Well sorry, but it is a factor. If you have a video card that only knows
how to display 256 colors, then you aren't going to get Gainsboro.
The color "Gainsboro" would likely be defined in some web standard. As
long as the browsers *rendering engine* can interpret what Gainsboro
should be, it'll display fine.

And, what web standard would that be? There are the colors defined as the
"Web Safe" colors and, yes, these colors do have names associated with them.
But the translation of those names into RGB values is in no way guaranteed
to happen in the same way from system to system.
The code that you are working on is executed server side. The resultant
output of this execution is valid HTML.

Stop right there. If you look at the resulting output, you will see that it
is not only HTML, but could also consist of CSS, static text and JavaScript
depending on the Web Forms control you were using. And, in this example the
resulting code would contain NOT the RGB value, but a CLIENT side reference
to Gainsboro. Try it for yourself and see.
The Color struct cotains definitions for a set number of colors. If you
want to use a colour that is not provided, then you use the RGB
representation instead.

Gee, that sounds like what I said.
 
Z

Zanna

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.

What is the error?

in C# (case sensitive) you need to write

btnSample.BackColor = Color.Gainsboro;

It's really no matther if the value came from the Web palette or it is in
RGB: it's a System.Drawing.Color and this is all you need.
 
S

Scott M.

The problem is that Gainsboro doesn't get converted to an RGB when the code
is delivered to the client. Cascading Style Sheet code is produced with the
color name Gainsboro still intact. The use of the color name in the client
code is producing different colors depending on the client that is receiving
the code. There is no error message.

If you've read this thread, you'll see that the solution is not to use the
color name Gainsboro and to use the RGB value for it instead.
 
B

Brendan Green

Scott M. said:
Well sorry, but it is a factor. If you have a video card that only knows
how to display 256 colors, then you aren't going to get Gainsboro.

No, you don't get Gainsboro. You get something that is converted down.
Still, the video card has no impact to the generation of the website. The
browser takes the value Gainsboro and converts it to some color that is used
when rendering the page. Get it? The browser takes care of the colours,
the video card just display's what it is given.
And, what web standard would that be? There are the colors defined as the
"Web Safe" colors and, yes, these colors do have names associated with
them. But the translation of those names into RGB values is in no way
guaranteed to happen in the same way from system to system.

You're missing the point. The browsers *rendering engine* is responsible
for displaying the web page. If its a known colour in, say, CSS, then the
browser will know what to do with it, and display it appropriately.
Stop right there. If you look at the resulting output, you will see that
it is not only HTML, but could also consist of CSS, static text and
JavaScript depending on the Web Forms control you were using. And, in
this example the resulting code would contain NOT the RGB value, but a
CLIENT side reference to Gainsboro. Try it for yourself and see.

So you get CSS and static text? So what, I missed a couple of TLA's? The
end result is something that gets interpreted by the browser. I am trying
to make the distinction between server side and client side processing.
Gee, that sounds like what I said.

Yes, I am reiterating the fact, which I thought would be prudent, given that
some of the earlier stuff that you wrote was confusing, and not related to
the problem at hand.
 
S

Scott M.

You are missing the point completely. I do "get it" and have "gotten it"
for the last 15 years since I've been doing and teaching "it". I never said
the video card has an impact on the code generated for the web site (and
yet, you keep telling me that I'm wrong and that I did). I said that color
names should not be used because different video cards will render different
CLIENT side color names differently (it doesn't matter if the browser
translates Gainsboro into an RGB if that is an RGB the video card can't
render correctly).

In short, you should not be using color names in CLIENT side code. If you
use Color.Gainsboro (SERVER code), the CLR will NOT convert that to an RGB
value to be sent to the CLIENT. It creates CSS for the control and
continues to refer to Gainsboro and round and round we go.

Now, lets consider that it is entirely possible with some of the more
obscure color names that different browsers are going to interpret what RGB
the color name should be translated to, which will result in different
colors being seen in the client.
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top