遍历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)
1.常用调用方法 public partial class UCRights : UserControl { private readonly int LOCATIONY; private DataTable MENU = new DataTable(); private BLL.User oUser = new HRPOWER.BLL.User(); public UCRights() { InitializeComponent(); LOCATIONY = panRightMenu_Top.