在打开表单之前,设置所有标签字体 [英] Set all Labels Font before opening the Form
本文介绍了在打开表单之前,设置所有标签字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在打开表单之前,我使用以下代码检查其标签是否更改了字体
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?
推荐答案
尝试一下;
foreach (Control c in this.Controls)
{
if (c is Label)
c.Font = usefontgrid;
}
或
foreach (var c in this.Controls.OfType<Label>())
{
c.Font = usefontgrid;
}
这篇关于在打开表单之前,设置所有标签字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文