My form has hundreds of controls: menus, panels, splitters, labels, text boxes, you name it.
Is there a way to disable every control except for a single button?
You can do a recursive call to disable all of the controls involved. Then you have to enable your button and any parent containers.
private void Form1_Load(object sender, EventArgs e) {
DisableControls(this);
EnableControls(Button1);
}
private void DisableControls(Control con) {
foreach (Control c in con.Controls) {
DisableControls(c);
}
con.Enabled = false;
}
private void EnableControls(Control con) {
if (con != null) {
con.Enabled = true;
EnableControls(con.Parent);
}
}