Solved

c# Net Set Label Colour

Posted on 2011-03-08
4
622 Views
Last Modified: 2012-05-11
I have the below i can use to set the fore/back colour of a label but i want to be able to set it to a hex value, how can i do this ?

(e.Row.FindControl("lblGroupName") as Label).BackColor = System.Drawing.Color.Red;

0
Comment
Question by:LBGUC04
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 35068783
Can you try the following:

(e.Row.FindControl("lblGroupName") as Label).BackColor  = Color.FromArgb(Int32.Parse(child.InnerText.Replace("#",""),System.Globalization.NumberStyles.HexNumber));

OR

string hex = "0xFF0000";  
int red   = HexToInt(hex.SubString(2, 2));  
int green = HexToInt(hex.SubString(4, 2));  
int blue  = HexToInt(hex.SubString(6, 2));  
(e.Row.FindControl("lblGroupName") as Label).BackColor  = Color.FromArgb(red, green, blue);  

0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 35068788
Try:
(e.Row.FindControl("lblGroupName") as Label).BackColor = System.Color.FromName("FF0000");

Open in new window

0
 
LVL 10

Expert Comment

by:Asim Nazir
ID: 35068822
You can also use:

 
Color.FromArgb(Int32.Parse(child.InnerText.Replace("#",""),System.Globalization.NumberStyles.HexNumber));

Open in new window

0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question