在C#Windows窗体中找到所有控件... ??? [英] Find all controls in a c# windows Form...???
问题描述
大家好,
我很少有1个splitcontainer的形式.在拆分容器的面板内部放置了2个datagridview.
在运行时,我想获取datagridviews的名称...
我在窗体的控件中使用了for循环....仅显示splitcontainer ...
我无法按名称获取控件...仅在运行时,我将获取Datagridviews的名称...
我无法通过递归获得控件,如果要递归地找到控件,我必须知道控件的名称...但是仅在搜索后,我才会知道控件的名称...
该怎么做??
我如何在父控件中获取所有子控件...
提前谢谢...
Mydeen.
Hello All,
I have few forms having 1 splitcontainer. And Inside the panels of split container I have dropped 2 datagridview.
In runtime I want to get the name of the datagridviews...
I have used a for loop through the controls of a form.......It is showing only the splitcontainer...
I cannot get the controls by name... In runtime only i will get the name of the Datagridviews...
I cannot get the controls by recursive, if I am going to find a control recursively I must know the name of the control... however I will come to know the name of the control after the search only...
How to do this??
How can i get the all child controls inside a parent control...
Thanks in advance...
Mydeen.
推荐答案
尝试以下操作...
Try the following...
private void FindControl(Control ctrl, string name)
{
if (ctrl.Name.Equals(name))
{
MessageBox.Show(ctrl.Name);
return;
}
foreach (Control ctr in ctrl.Controls)
{
FindControl(ctr, name);
}
}
问候,
Vineeth
Regards,
Vineeth
请参见此处 [
这篇关于在C#Windows窗体中找到所有控件... ???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!