Return to Snippet

Revision: 23255
at February 2, 2010 11:05 by pckujawa


Updated Code
foreach (var control in Controls.All()) {}

   public static IEnumerable<Control> All(this Control.ControlCollection controls)
   {
      foreach (Control control in controls)
      {
         foreach (Control grandChild in control.Controls.All())
            yield return grandChild;
   
         yield return control;
      }
   }

Revision: 23254
at February 2, 2010 11:03 by pckujawa


Initial Code
foreach (var control in Controls.All())

Initial URL
http://www.devx.com/dotnet/Article/41639/0/page/3

Initial Description
Found in the above URL. Requires extension methods (C# 3.0+).

Initial Title
Enumerate all controls and sub-controls in a windows form

Initial Tags

                                

Initial Language
C#