学习型 ASP/PHP/ASP.NET 主机 30元/年全能 ASP/PHP/ASP.NET 主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付
发新话题
打印

遍历窗体上所有的控件的另类办法

遍历窗体上所有的控件的另类办法

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);
                }
            }
        }

TOP

给点中文嘛,小哥,一堆代码都不知道该看哪了

TOP

发新话题