Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / August 2005

Tip: Looking for answers? Try searching our database.

Colors

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paul Smith - 20 Aug 2005 00:28 GMT
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!
Scott M. - 20 Aug 2005 00:41 GMT
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.

>I have a button on my web page the backcolor of which I want to change:
>
[quoted text clipped - 6 lines]
>
> Help!
Paul Smith - 20 Aug 2005 07:29 GMT
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

> color.fromArgb(rr, gg, bb)
>
[quoted text clipped - 15 lines]
>>
>> Help!
Scott M. - 20 Aug 2005 18:47 GMT
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

> 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
[quoted text clipped - 27 lines]
>>>
>>> Help!
Paul Smith - 20 Aug 2005 21:17 GMT
Scott,

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

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
[quoted text clipped - 63 lines]
>>>>
>>>> Help!
Scott M. - 21 Aug 2005 00:49 GMT
No problem.  Good luck.

> Scott,
>
[quoted text clipped - 70 lines]
>>>>>
>>>>> Help!
Brendan Green - 26 Aug 2005 03:23 GMT
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.

> 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
[quoted text clipped - 63 lines]
>>>>
>>>> Help!
Scott M. - 27 Aug 2005 04:50 GMT
> 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.

>> While the Properties window does show Gainsboro in the list, remember
>> that the values you select in the Properties window for web forms
[quoted text clipped - 63 lines]
>>>>>
>>>>> Help!
Brendan Green - 29 Aug 2005 04:01 GMT
>> 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.

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.

>> The color "Gainsboro" would likely be defined in some web standard.  As
>> long as the browsers *rendering engine* can interpret what Gainsboro
[quoted text clipped - 4 lines]
> 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.

>> The code that you are working on is executed server side.  The resultant
>> output of this execution is valid HTML.
[quoted text clipped - 4 lines]
> 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.

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

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.

>>> While the Properties window does show Gainsboro in the list, remember
>>> that the values you select in the Properties window for web forms
[quoted text clipped - 66 lines]
>>>>>>
>>>>>> Help!
Scott M. - 29 Aug 2005 16:12 GMT
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.

>>> 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.
[quoted text clipped - 114 lines]
>>>>>>>
>>>>>>> Help!
Zanna - 27 Aug 2005 11:54 GMT
"Paul Smith" <pws@twelve.me.uk> ha scritto nel messaggio
news:43066b16$0$97123$ed2619ec@ptn-nntp-

> I have a button on my web page the backcolor of which I want to change:
>
[quoted text clipped - 4 lines]
> 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.

--
.Net Reporting tool: http://www.neodatatype.net
Scott M. - 27 Aug 2005 18:17 GMT
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.

> "Paul Smith" <pws@twelve.me.uk> ha scritto nel messaggio
> news:43066b16$0$97123$ed2619ec@ptn-nntp-
[quoted text clipped - 19 lines]
> --
> .Net Reporting tool: http://www.neodatatype.net

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.