Solved

c# Net Set Label Colour

Posted on 2011-03-08
4
616 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: 35068794
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
"The resource cannot be found" 1 42
C# LINQ 5 41
Difference between Highcharts and Mapbox 10 44
Why am I losing my session variable value 11 39
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

732 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