/// <summary> /// 查找指定類型控件 /// </summary> /// <typeparam name="T">待查找控件類型</typeparam> /// <param name="ctl">控件所在容器</param> /// <param name="act">找到后執行的操作</param> private void FindCtl<T>(Control ctl, Action<T> act) where T : Control { T tmp = null; Stack<Control> ctls = new Stack<Control>(); for (int i = 0; i < ctl.Controls.Count; i++) { if (ctl.Controls[i].Controls.Count > 0 || (ctl.Controls[i] as T) != null) { ctls.Push(ctl.Controls[i]); } } do { Control tmpCtl = ctls.Pop(); tmp = tmpCtl as T; if (tmp == null && tmpCtl.Controls.Count > 0) { for (int i = 0; i < tmpCtl.Controls.Count; i++) { ctls.Push(tmpCtl.Controls[i]); } } if (tmp != null) { act(tmp); } } while (ctls.Count > 0); }