I have 25 panel control (Visible false). I want to make it visible.
But it doesn' work: (Error 1 'string' does not contain a definition for 'Visible' and no extension method 'Visible' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?) )
for (int i = 0; i < 25; i++)
{
string panelID = "panel" + i.ToString();
panelID.Visible = true;
}
Help
Your code is wrong in so many fronts.
As it is, what you're doing is creating 25 strings with values
panel0,panel1,panel2etc., and trying to assign a value to a property of it. But strings don't contain a property namedVisible, so obviously you'll get an error.What you want to do is get hold of controls of type
Panelin your form, and set their values.Caveat: the above will only find
Panelcontrols in your topmost form. If there are controls that are nested, you'd want to perhaps write a method to recursively find them. Above is just to give you the idea.In addition, if you have multiple
Panelcontrols and if you only want to set the property of those panels names fit your naming convention you can filter them out.Here, you can look for correct panel name by using a
Regex, use a custom function etc.