5 Years
Discussion Span
Last Post by deceptikon

If they are name sequentially you can use a loop and build each name using the indexer of the loop. So if they are named PictureBox1,PictureBox2,etc., the code could look something like this:

For I = 1 to 4
    Me.Controls("PictureBox"+I.ToString).Visible = True

The controls collection allows indexing by name. I used the Controls collection of the default form, but any control that contains the controls will have a Controls collection.

Edited by tinstaafl


Me is the VB.NET equivalent of C#'s this. So in C# you'd write tinstaafl's suggestion as:

for (int i = 0; i < 4; i++)
    this.Controls("pictureBox" + i).Visible = true;

Though this depends on each PictureBox being default named as if you dropped them onto the form and didn't change the name. It also assumes that all four PictureBox controls exist directly on whatever control/form you're referencing by this.

All in all, pretty big assumptions given how vague your question is. I'm also not sure that the loop does what you want (actually, I'm pretty sure it doesn't). We need more information as to the exact behavior you're looking for before any specific suggestions can be made.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.