Reputation: 88
What I have:
label4.Show();
label5.Show();
pictureBox3.Show();
textBox1.Show();
button3.Show();
What I need (example, but doesn't work):
Object[] arr = new Object[] { label4,label5,pictureBox3,textBox1,button3 };
foreach (Object o in arr)
{
o.Show();
}
Is it to possible to do something like this code?
Upvotes: 1
Views: 112
Reputation: 5415
Use Control[]
instead of Object[]
. Control
has the Show
method, see here.
When I need to do something like this, I usually find it more convenient to group controls into a Panel
, then you can just show and hide the panel without having to muck with the individual controls. That only works if the controls are arranged close together on your form, but if they are you might consider this approach.
Upvotes: 6