Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 11th, 2003, 08:53 AM
Authorized User
 
Join Date: Jun 2003
Location: , , Yugoslavia.
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default color

Hi
In btnClick event i want to change back color of label

lbl.BackColor=Color.Red for example

but problem is than i have color like this #F9DA00
and lbl.BackColor = "#F9DA00" does not work.
Reply With Quote
  #2 (permalink)  
Old December 11th, 2003, 09:17 AM
Friend of Wrox
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,346
Thanks: 0
Thanked 5 Times in 5 Posts
Default

use imports system.drawing.color

then just use backcolor.red



Reply With Quote
  #3 (permalink)  
Old December 11th, 2003, 09:39 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,111
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Here is one way.

Create a style:
<style>
        .mystyle { background-COLOR: #f9da00; }
</style>

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label1.CssClass = "mystyle"
End Sub


Reply With Quote
  #4 (permalink)  
Old December 11th, 2003, 02:38 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,413
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Take a look at the Color.FromArgb() method.

You specify the red, green and blue integer values. You'll need to convert your hex to decimal.

Peter
------------------------------------------------------
Work smarter, not harder.
Reply With Quote
  #5 (permalink)  
Old December 11th, 2003, 03:41 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,111
Thanks: 0
Thanked 3 Times in 3 Posts
Default

That's a rather complex way wouldn't you think Peter?

I had to open fireworks and enter a color then find its RGB int values.

which are: (249, 218, 0)

and then i added Label1.BackColor = Color.FromArgb(249, 218, 0)

Is there an easier way to obtain the RGB values?

BTW acko this is the answer:
Label1.BackColor = Color.FromArgb(249, 218, 0)

Reply With Quote
  #6 (permalink)  
Old December 11th, 2003, 05:30 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,413
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The original poster asked "how do I make lbl.BackColor = "#F9DA00" work?"
In order to set a web control attribute that is of the System.Color type you need to provide it with such. In VB.net you do that with the function I suggested if you want to use a specific color vs. a predefined system color. Unfortunately, yes, this is a bit of a pain and somewhat complicated.

You couldn't do the hex conversion in your head? ;)
Reply With Quote
  #7 (permalink)  
Old December 31st, 2003, 02:20 PM
Registered User
 
Join Date: Dec 2003
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try This:

    Me.BackColor = System.Drawing.ColorTranslator.FromHtml("&H00FFFF" )

Also works like this:

    Me.BackColor = System.Drawing.ColorTranslator.FromHtml("cornflowe rblue")



Reply With Quote
  #8 (permalink)  
Old December 31st, 2003, 11:41 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,346
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I agree that this is stupid. When you pick a color in the properties window you see a value of #FF8080. Why can't you just specify a color like that? I know it requies that you enter a value of System.Color, but if Microsoft suppplies you with a value like that, why can't you spcify a value like that in code? To me it is just another inconsistance of .NET. Any ideas why it works this way? I am curious as to why this is.

Thanks,

Jim

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
color histogram kokilakok Pro PHP 0 February 1st, 2007 04:11 AM
re: color change jack_in_black ASP.NET 2.0 Professional 0 July 11th, 2006 07:24 AM
Color distortion Snib HTML Code Clinic 6 January 20th, 2005 01:49 AM
from color="red" to color='red' juaniux XSLT 2 November 16th, 2004 03:18 PM
Using Color Palette Monica Pro VB.NET 2002/2003 3 January 30th, 2004 05:06 AM



All times are GMT -4. The time now is 02:58 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.