private void SetVisible(Control control) { foreach (Control c in control.Controls) { if (c.HasChildren) { SetVisible(c); } else { var btn = c as Button; if (btn != null) btn.Visible = false; } } }