Click here to Skip to main content
16,011,611 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi
In C#.net windows based application..

I want to set common properties like color, font size, height, width, font type of all the label, button and textbox controls in C#.net forms .......

How can i do it ......
Please provide me code for that ......

i have tried that code , but it's not working ........
C#
private void ResetAllControlsBackColor(Control control)
{
   control.BackColor = SystemColors.Control;
   control.ForeColor = SystemColors.ControlText;
   if(control.HasChildren)
   {
      // Recursively call this method for each child control.
      foreach(Control childControl in control.Controls)
      {
         ResetAllControlsBackColor(childControl);
      }
   }
}
Posted
Updated 6-Sep-13 8:53am
v3
Comments
Richard C Bishop 6-Sep-13 14:56pm    
Well, you are not assigning any color to the Fore and Back color of your control. That might be one place to start. Does the code you have compile?
safal.786 6-Sep-13 15:00pm    
thanks ...for ur solution......

1 solution

The code you show looks just like the example you took it from - which being MSDN means it should work.
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.haschildren.aspx[^]

There are two possibilities I can think of immediately:
1) It is doing exactly what it should, but none of your controls have had the Fore- or Back- Color property changed from the deafult, so it doesn't show up as doing anything.
2) You aren't calling the method with teh correct control in the first instance, so it doesn't reach any controls with a modified Fore- or Back- Color property.

Try calling it from a Button.Click event handler, and call the method like this:
C#
ResetAllControlsBackColor(this);
Which will affect every control in the form (including the form itself)
 
Share this answer
 

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