Enumerate all controls and sub-controls in a windows form

/ Published in: C#
Save to your folder(s)

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

Copy this code and paste it in your HTML
  1. foreach (var control in Controls.All()) {}
  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;
  10. yield return control;
  11. }
  12. }

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

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.