在写程序的时候经常会动态找某个控件,写了个函数方便查找,第一个参数是要查找的控件容器,第2个参数是控件的名称,返回的是一个控件对象,使用的时候转换一下类型就可以了
1
private Control seachControl(Control it,string id)
2
{
3
Control oo=null;
4
foreach(Control c in it.Controls)
5
{
6
oo=c.FindControl(id);
7
if (oo!=null)
8
{
9
10
break;
11
}
12
else
13
{
14
if (c.Controls.Count>0)
15
{
16
oo=seachControl(c,id);
17
if (oo!=null)
18
{
19
return oo;
20
}
21
}
22
}
23
}
24
return oo;
25
}
private Control seachControl(Control it,string id)2

{3
Control oo=null;4
foreach(Control c in it.Controls)5

{6
oo=c.FindControl(id);7
if (oo!=null)8

{9
10
break;11
}12
else13

{14
if (c.Controls.Count>0)15

{16
oo=seachControl(c,id);17
if (oo!=null)18

{19
return oo;20
}21
}22
}23
}24
return oo;25
}
本文介绍了一种用于在.NET应用程序中递归查找特定ID控件的方法。通过提供一个通用函数,可以在复杂的用户界面层级中定位指定的控件实例。
860

被折叠的 条评论
为什么被折叠?



