遍历窗体上所有的控件的另类办法
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);
}
}
}