本文介绍了在当前项目的表单中查找表单控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我想在当前项目的所有形式中找到TextBox控件并更改其字体.
我想要使用C#Windows应用程序进行解决方案编码.
如果可能的话,请逐步给我解决方案,因为我在编程方面比较新鲜.
感谢所有人
Ruchik.
Hi All
I want to find TextBox control in among all the forms of current project and change their fonts.
I want solution coding with c# windows application.
If possible please give me solution step by step because i m fresher in programming.
Thanks to all
Ruchik.
推荐答案
private void ChangeFontInTextBoxes(Control container)
{
foreach (Control ctrl in container.Controls)
{
if (ctrl is TextBox)
{
// set the font or other desired properties
}
else
{
if (ctrl.HasChildren)
{
ChangeFontInTextBoxes(ctrl);
}
}
}
}
我会用这样的形式来称呼它:
and I''d call it from the form like this:
ChangeFontInTextBoxes(this);
上面的代码使用递归(用谷歌浏览).
The code above uses recursion (google it).
class MyTextBox : TextBox
{
public MyTextBox()
{
Font = ...;
}
}
这篇关于在当前项目的表单中查找表单控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!