private GetControls(Control ctrl) { foreach(Control c in ctrl.Controls) { // 处理c if(c.HasChildren) { GetControls(c); // 递归 } } }
foreach (Component comp in this.components.Components) MessageBox.Show(comp.GetType().Name);
假如我要检查所有MDIChichren窗,在下面的代码中this要换成foreach中的f, 请问怎么改写?谢谢foreach (Form f in this.MdiChildren) { foreach (Component comp in this.components.Components) //因为this代表当前窗体对象,若改为f,f后没components,请问怎么改 MessageBox.Show(comp.GetType().Name); }
谢谢楼上的 我若将this.components.Components中的this换为foreach (Form f in this.MdiChildren)中的f,系统提示出错的
不一定所有窗口都有组件的foreach (Form f in this.MdiChildren) if(f.componets != null) foreach (Component comp in this.components.Components) MessageBox.Show(comp.GetType().Name);
忘了把this改成f了:foreach (Form f in this.MdiChildren) if(f.componets != null) foreach (Component comp in f.components.Components) MessageBox.Show(comp.GetType().Name);
{
foreach(Control c in ctrl.Controls)
{
// 处理c
if(c.HasChildren)
{
GetControls(c); // 递归
}
}
}
MessageBox.Show(comp.GetType().Name);
请问怎么改写?谢谢foreach (Form f in this.MdiChildren)
{
foreach (Component comp in this.components.Components)
//因为this代表当前窗体对象,若改为f,f后没components,请问怎么改
MessageBox.Show(comp.GetType().Name);
}
我若将this.components.Components中的this换为foreach (Form f in this.MdiChildren)中的f,系统提示出错的
if(f.componets != null)
foreach (Component comp in this.components.Components)
MessageBox.Show(comp.GetType().Name);
if(f.componets != null)
foreach (Component comp in f.components.Components)
MessageBox.Show(comp.GetType().Name);