I want to change the font to labels (Label1 to Label10) at the same time, I explain:
I have a Form WindowsForms
in which I have a panel
within that panel I have added 2 user controls UserControls
, within both UserControls
I have several labels
, which do not belong to the UserControls
but they are above the UserControl
added in them from the form.
This image to illustrate, The
Panel
is theGris Oscuro
of background, the UserControl contains 1 icon and a title that belongs to the user control including the part of the light gray background color. The only objects that do not belong to the user controls are the internal labels that can be observed.
But when executing the function it also changes the source to the titles of UserControls
that are also Labels but do not belong to the form as such, but come from the UserControl, I do it this way, with a function recursive :
private void cambiar_fuentes(Control contenedor)
{
foreach (Control control in contenedor.Controls)
{
if (control.Controls.Count > 0)
cambiar_fuentes(control);
else
{
if (control is Label) ((Label)control ).Font = new Font("Arial", 10, FontStyle.Regular);
}
}
}
Calling the function:
cambiar_fuentes(panel1);
How can I change only the source only of the labels (1 to 10) that belong to the form as such?
EDITED
Designer.cs Code Snippet:
this.panel1.BackColor = System.Drawing.Color.Transparent;
this.panel1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel1.Controls.Add(this.flowLayoutPanel1);
this.panel1.Location = new System.Drawing.Point(1, 1);
this.panel1.MaximumSize = new System.Drawing.Size(295, 2);
this.panel1.MinimumSize = new System.Drawing.Size(2, 732);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(295, 732);
this.panel1.TabIndex = 5;
this.flowLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.flowLayoutPanel1.AutoScroll = true;
this.flowLayoutPanel1.BackColor = System.Drawing.Color.Transparent;
this.flowLayoutPanel1.Controls.Add(this.userControl1);
this.flowLayoutPanel1.Controls.Add(this.userControl2);
this.flowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
this.flowLayoutPanel1.Location = new System.Drawing.Point(1, 34);
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.flowLayoutPanel1.Size = new System.Drawing.Size(292, 684);
this.flowLayoutPanel1.TabIndex = 29;
this.flowLayoutPanel1.WrapContents = false;
this.userControl1.Controls.Add(this.label1);
this.userControl1.Controls.Add(this.label2);
Here
this.uersControl1.Controls.Add(this.label1);
the other labels continue ...
Environment: Visual Studio 2010 & .NET Netframework 4.