i have 4 pictureBox which are hidden, and now i want to show them one by one, how it can be done?????

Recommended Answers

All 3 Replies

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
Next

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.

I can't understand what it "Me.Controls" doest mean?????

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.