编程论坛's Archiver

heyu52 发表于 2008-5-11 23:10

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

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-5-12 12:18

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

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.