Set all Labels Font before opening the Form
c#, label, sql, visual-studio-2010
Solution
Try this;
foreach (Control c in this.Controls)
{
if (c is Label)
c.Font = usefontgrid;
}
Or
foreach (var c in this.Controls.OfType<Label>())
{
c.Font = usefontgrid;
}
Problem
Before opening the form I used following code to check if its label then change the font ``` foreach (Label ctl in frm.Controls) { ctl.Font = usefontgrid; } ``` But on first line return error because it check other control types such as textbox or button,etc. How can I check if the object is only label then go to for each?