Search code examples
c#.netcontrolstoolstrip

.NET Referencing similar controls


I have multiple toolstrip controls in my application and was looking for a way to hide them all at once.

E.g.

allToolStrips.Visible = false;

instead of

toolstrip1.Visible = false;
toolstrip2.Visible = false;
...
toolstripn.Visible = false;

I'm using C# if it matters.


Solution

  • easy one

    foreach(Control ctrl in this.Controls)
    {           
             if(ctrl.GetType() ==typeof(ToolStrip))
    
             ctrl.Visible=false;    
    
    }