Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Navigate through Controls and Components
- public void Traverse(Control cnt)
- {
- foreach (Control c in cnt.Controls)
- {
- if (c.HasChildren) Traverse(c);
- Debug.Print(c.Name); // For debugging purpose only
- // My code goes here
- }
- }
- private void GetControls(ICollection controls, IList<string> names)
- {
- foreach (var ctl in controls)
- {
- if (ctl is IComponent)
- {
- var name = ctl.GetType().GetProperty("Name");
- if (name != null)
- names.Add((string) name.GetValue(ctl, null));
- foreach (var property in ctl.GetType().GetProperties())
- {
- var prop = property.GetValue(ctl, null);
- if (prop is ICollection)
- GetControls((ICollection)prop, names);
- }
- }
- }
- }
- var ctlNames = new List<string>();
- GetControls(Controls, ctlNames);
Add Comment
Please, Sign In to add comment