Click here to Skip to main content
16,010,523 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to set common font size and color properties of multiple label and textbox controls in same c#.net windows form.


plz provide the code with solution.........
Posted

try it:-
C#
foreach (Control ctr in this.Controls)
        {
            ctr.Font = SystemFonts.IconTitleFont;
            // controls in groupboxes are not child of main form
            if (ctr.HasChildren)
            {
                foreach (Control childControl in ctr.Controls)
                {
                    childControl.Font = SystemFonts.IconTitleFont;
                }
            }
        }
 
Share this answer
 
Comments
shiva2239 9-Apr-15 7:52am    
I have changed a littele bcz of some error.

foreach (System.Windows.Forms.Control ctr in this.Controls)
{
//ctr.Font = SystemFonts.IconTitleFont;
if (ctr.HasChildren)
{
foreach (System.Windows.Forms.Control childControl in ctr.Controls)
{
//childControl.Font = SystemFonts.IconTitleFont;
childControl.ForeColor = System.Drawing.Color.DarkSlateGray;
}
}
}

"Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Windows.Forms.Control'." When I run the application I am getting this error.HOw to set color for group of labels at a time.Plz suggets me.
Belowing code will help you...


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);
      }
   }
}
 
Share this answer
 
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 ........

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);
}
}
}
 
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