1

I have some windows forms that each has some controls including buttons,ComboBox,... and also in each form i have a Bindingnavigator control that i added some new Toolstrip buttons to it, how can i write a general method that get 3 parameters and iterate all controls on a form(including that toolstrip buttons) and enable/disable Enabled status of an special control? my method signature is like this:

Public SetStatusOf(Form frm,string controlName,bool status)
Masoud
  • 8,020
  • 12
  • 62
  • 123

1 Answers1

1

From the question, and from what I understood, you need this:

    foreach (Control c in frm.Controls)
    {
        if (c.Name.Equals(controlName))
            c.Enabled = status;
    }

but you can also directly use

frm.Controls[controlName].Enabled = status;
mihirj
  • 1,199
  • 9
  • 15
  • but 2 things: 1- with this code snippet i couldn't iterate all controls(controls with child controls) 2-ToolStripButton does not inherited from Control class – Masoud Jan 23 '13 at 09:51