If all the Button
s are on the form you can try using Linq:
using System.Linq;
...
Button[] ButtonArray = Controls
.OfType<Button>()
.ToArray();
Edit: in case you have some buttons within groupboxes, panels (i.e. not directly on the form, but on some kind of container), you have to elaborate the code into something like this
private static IEnumerable<Button> GetAllButtons(Control control) {
IEnumerable<Control> controls = control.Controls.OfType<Control>();
return controls
.OfType<Button>()
.Concat<Button>(controls
.SelectMany(ctrl => GetAllButtons(ctrl)));
}
...
Button[] ButtonArray = GetAllButtons(this).ToArray();
See How to get ALL child controls of a Windows Forms form of a specific type (Button/Textbox)? for details