void buttonMode(string mode) { bool b1Status = false; if (mode == "online") { b1Status = false; SendData.Enabled = !b1Status; SendData.Focus(); } else if (mode == "offline") { b1Status = true; SendData.Enabled = !b1Status; button1.Focus(); } List <Control> list = new List <Control>(); GetAllControl(this, list); foreach (Control control in list) { if (control.GetType() == typeof(Button)) { Button tmp = (Button)control; if (tmp.Name == "button1") { tmp.Enabled = b1Status; } else { tmp.Enabled = !b1Status; } } if (control.GetType() == typeof(GroupBox)) { ((GroupBox)control).Enabled = !b1Status; } } }