Guest User

Untitled

a guest
Aug 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. Navigate through Controls and Components
  2. public void Traverse(Control cnt)
  3. {
  4. foreach (Control c in cnt.Controls)
  5. {
  6. if (c.HasChildren) Traverse(c);
  7. Debug.Print(c.Name); // For debugging purpose only
  8. // My code goes here
  9. }
  10. }
  11.  
  12. private void GetControls(ICollection controls, IList<string> names)
  13. {
  14. foreach (var ctl in controls)
  15. {
  16. if (ctl is IComponent)
  17. {
  18. var name = ctl.GetType().GetProperty("Name");
  19. if (name != null)
  20. names.Add((string) name.GetValue(ctl, null));
  21.  
  22. foreach (var property in ctl.GetType().GetProperties())
  23. {
  24. var prop = property.GetValue(ctl, null);
  25. if (prop is ICollection)
  26. GetControls((ICollection)prop, names);
  27. }
  28. }
  29. }
  30. }
  31.  
  32. var ctlNames = new List<string>();
  33. GetControls(Controls, ctlNames);
Add Comment
Please, Sign In to add comment