标题:遍历窗体上所有的控件的另类办法
取消只看楼主
heyu52
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2008-4-11
 问题点数:0 回复次数:0 
遍历窗体上所有的控件的另类办法
private List<Control> _allControls = new List<Control>();

private void InitializeControlList()
        {
            Queue<Control.ControlCollection> q = new Queue<Control.ControlCollection>();
            q.Enqueue(this.Controls);

            while (q.Count > 0)
            {
                Control.ControlCollection controls = (Control.ControlCollection)q.Dequeue();
                if (controls == null || controls.Count == 0) continue;

                foreach (Control control in controls)
                {
                    q.Enqueue(control.Controls);

                    if (this.IsMdiChild)
                    {
                        if (control is System.Windows.Forms.ToolStrip || control is System.Windows.Forms.ToolStripDropDown)
                        {
                            continue;
                        }
                    }

                    this._allControls.Add(control);
                }
            }
        }
搜索更多相关主题的帖子: 遍历 控件 窗体 另类 办法 
2008-05-11 23:10



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-213796-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.368534 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved