(c#)WinForm遍历所有控件


遍历WinForm中的所有控件,只执行一次以下语句是不行的

foreach (Control ctl in this.Controls)
{
}

这样只能遍历到第一层控件,子控件是遍历不到的,要想遍历所有存在的控件,需要递归解决

//伪代码如下

 void EnumControls(Control container)
{
   foreach(Control c in container.Controls)
   {
       //c is the child control here
       EnumControls(c);        
   }
}

//调用
EnumControls(this);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM