Posted By

pckujawa on 02/02/10


Tagged

WinForms enumerate


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

thastyle
Priestd09


Enumerate all controls and sub-controls in a windows form


 / Published in: C#
 

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

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

  1. foreach (var control in Controls.All()) {}
  2.  
  3. public static IEnumerable<Control> All(this Control.ControlCollection controls)
  4. {
  5. foreach (Control control in controls)
  6. {
  7. foreach (Control grandChild in control.Controls.All())
  8. yield return grandChild;
  9.  
  10. yield return control;
  11. }
  12. }

Report this snippet  

You need to login to post a comment.