Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 637
  • Last Modified:

c# Net Set Label Colour

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
LBGUC04
Asked:
LBGUC04
  • 2
1 Solution
 
DhaestCommented:
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
 
Carl TawnSystems and Integration DeveloperCommented:
Try:
(e.Row.FindControl("lblGroupName") as Label).BackColor = System.Color.FromName("FF0000");

Open in new window

0
 
Asim NazirCommented:
You can also use:

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

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now