如何在其他控件中找到控件 [英] how find control in other controls
本文介绍了如何在其他控件中找到控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hi
i希望在supertabcontrol1中的supertabcontrolpanel1中找到checkboxX控件supertabcontrol1中的supertabitem1
foreach (控制con1 在控件[ superTabControl1]。控件)
{
尝试
{
foreach (控制con2 在 con1.Controls [ superTabItem1]。控件)
{
foreach (控制con3 in con2.Controls [ superTabControlPanel1]。控件)
{
bool dd =((CheckBoxX)con3).Checked; // 它是checkboxX (dotnetbar componentsnets)
}
}
}
catch (例外)
{
}
}
我如何
解决方案
就个人而言,我会把它设置得更通用,即递归方法。
public 控制FindControlRecursive(控件控件,字符串 id)
{
if (control == null ) throw new ArgumentNullException( control);
if (control.ID == id) return control;
foreach (控制子 control.Controls)
{
控制c = FindControlRecursive(child,id);
if (c!= null ) return c;
}
return null ;
}
然后你就可以这样叫它
CheckBox chkbx =(CheckBox)FindControlRecursive(superTabControl1, idofcheckbox)
hi
i want find checkboxX control in supertabcontrolpanel1 in supertabitem1 in supertabcontrol1
foreach (Control con1 in Controls["superTabControl1"].Controls)
{
try
{
foreach (Control con2 in con1.Controls["superTabItem1"].Controls)
{
foreach (Control con3 in con2.Controls["superTabControlPanel1"].Controls)
{
bool dd = ((CheckBoxX)con3).Checked;//it is checkboxX (dotnetbar componenets)
}
}
}
catch (Exception)
{
}
}
how do i
解决方案
Personally I would set it up a bit more generic, i.e. a recursive method.
public Control FindControlRecursive(Control control, string id) { if (control == null) throw new ArgumentNullException("control"); if (control.ID == id) return control; foreach (Control child in control.Controls) { Control c = FindControlRecursive(child, id); if (c != null) return c; } return null; }
And then you can call it like this
CheckBox chkbx = (CheckBox)FindControlRecursive(superTabControl1, "idofcheckbox")
这篇关于如何在其他控件中找到控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文