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

December 11th, 2003, 09:53 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

December 11th, 2003, 10:17 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
use imports system.drawing.color
then just use backcolor.red
|
|

December 11th, 2003, 10:39 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|
|

December 11th, 2003, 03:38 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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.
|
|

December 11th, 2003, 04:41 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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)
|
|

December 11th, 2003, 06:30 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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? ;)
|
|

December 31st, 2003, 03:20 PM
|
|
Registered User
|
|
Join Date: Dec 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Try This:
Me.BackColor = System.Drawing.ColorTranslator.FromHtml("&H00FFFF" )
Also works like this:
Me.BackColor = System.Drawing.ColorTranslator.FromHtml("cornflowe rblue")
|
|

January 1st, 2004, 12:41 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
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
|
|
 |