Advertisement
drkbl

Recursive access of controls

May 29th, 2021
1,611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.49 KB | None | 0 0
  1. // Recursive access of controls of a root control
  2. // Source: https://social.msdn.microsoft.com/Forums/vstudio/en-US/04d08bfb-2214-4636-b12d-b98f33caa4c4/recursive-search-of-all-controls-on-a-form
  3. private void ProcessAllControls(Control rootControl, Action<Control> action)
  4. {
  5.     foreach (Control childControl in rootControl.Controls)
  6.     {
  7.         ProcessAllControls(childControl, action);
  8.         action(childControl);
  9.     }
  10. }
  11. // Use as: ProcessAllControls(this, ctrl => ctrl.Visible = false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement