Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 11th, 2003, 09:53 AM
Authorized User
 
Join Date: Jun 2003
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.
 
Old December 11th, 2003, 10:17 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

use imports system.drawing.color

then just use backcolor.red



 
Old December 11th, 2003, 10:39 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
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


 
Old December 11th, 2003, 03:38 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
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.
 
Old December 11th, 2003, 04:41 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
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)

 
Old December 11th, 2003, 06:30 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
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? ;)
 
Old December 31st, 2003, 03:20 PM
Registered User
 
Join Date: Dec 2003
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")



 
Old January 1st, 2004, 12:41 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
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






Similar Threads
Thread Thread Starter Forum Replies Last Post
color histogram kokilakok Pro PHP 0 February 1st, 2007 05: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 02:49 AM
from color="red" to color='red' juaniux XSLT 2 November 16th, 2004 04:18 PM
Using Color Palette Monica Pro VB.NET 2002/2003 3 January 30th, 2004 06:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.