Skip to content

Instantly share code, notes, and snippets.

@tjone270
Created September 22, 2019 22:44
Show Gist options
  • Save tjone270/8f3460435bd33f97c9192e55993b423c to your computer and use it in GitHub Desktop.
Save tjone270/8f3460435bd33f97c9192e55993b423c to your computer and use it in GitHub Desktop.
Get all WinForms controls on a form.
private IEnumerable<Control> GetAllControls(Control.ControlCollection controls) {
List<Control> all_controls = new List<Control>();
foreach (Control control in controls) {
if (control.GetType() == typeof(GroupBox)) {
all_controls.AddRange(GetAllControls(control.Controls));
}
all_controls.Add(control);
}
return all_controls;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment