Click here to Skip to main content
15,896,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to have Gray background, i tried with diffrent ways but did'nt work.

C#
using System.Drawing;
////
lbdetail.BackColor = System.Drawing.Color.Red;


How can I Use Custom color code like " #eee ".
Posted
Updated 15-Feb-12 0:13am
v3
Comments
BobJanova 10-Feb-12 8:58am    
Where are you trying to do this? In a web situation, setting properties on controls only works if you're in the pre-render portion of a request handler. Hooking this up to, for example, an AJAX handler (pure JS), won't do anything.

using System.Drawing;

Color colorName = System.Drawing.ColorTranslator.FromHtml("#eeee");
lbdetail.BackColor = colorName;

this code is working fine for me..try it..don forget to give proper hexadecimal colors :)

happy coding....
 
Share this answer
 
Include a namespace
using System.Drawing;

and whenever you want to change the color write
label1.backcolor=color.red;

if want to change the color when the form loads then you can write the code in
public form1()
{
InitializeComponent();
label1.backcolor=color.red;
}
or
forms load event..
 
Share this answer
 
v3
Comments
JawadHafiz 10-Feb-12 8:47am    
i am using on webform,


I tried but did'nt work
JawadHafiz wrote:
i am using on webform, I tried but did'nt work


Try this -
C#
lbdetail.ForeColor = System.Drawing.Color.Red;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900