Click here to Skip to main content
15,891,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I have created a Label dynamically the code is as below.

Label status = new Label();
status.ForeColor = System.Drawing.Color.Red;

and error is coming as below:-

'string' does not contain a definition for 'ForeColor' and no extension method 'ForeColor' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
Posted
Updated 14-Jul-15 21:51pm
v2
Comments
Sreekanth Mothukuru 15-Jul-15 3:24am    
You need to set foreColor property to label control and not to its text.
F-ES Sitecore 15-Jul-15 4:41am    
The code you have posted can't generate the error you have pasted. If you have surmised or paraphrased your code then please post the actual code, and check the exact line the error is happening on.

1 solution

Try this:
status.ForeColor = System.Drawing.Color.Red;
 
Share this answer
 
Comments
Merajuddin Ansari 15-Jul-15 3:28am    
same error:-
'string' does not contain a definition for 'ForeColor' and no extension method 'ForeColor' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
Ralf Meier 15-Jul-15 3:47am    
in this sample "Status" is the Name of the used Label.
ForeColor is the Property of the Label - not the Text ...
Merajuddin Ansari 15-Jul-15 3:50am    
I am doing same.
status.ForeColor = System.Drawing.Color.Red;
but still getting same error.
Sreekanth Mothukuru 15-Jul-15 4:03am    
Update your question to reflect the correct error message.
Ralf Meier 15-Jul-15 14:10pm    
Do you get an error or is still nothing happen ?
Is your dynamicly created Label member of the Parent.Controls.Collection ?
I think, it is usefull, to see more than 2 code-lines from you (and to hear something more from you).

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



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