Array of PictureBox controls

In my form I create a 10 x 10 array of PictureBox controls, like this:

public System.Windows.Forms.PictureBox[,] pBoxArray = new  System.Windows.Forms.PictureBox[10,10];

Then later I want to SHOW the images assigned to the PictureBox controls using a nest for loop.

How do I assign each picture box in the array to the Parent Form and make the image show up?
LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

smeggheadCommented:
for (int c1=0 ; c1<10 ; c1++)
{
   for (int c2=0 ; c2<10 ; c2++)
   {
       pBoxArray[c1,c2]=new PictureBox();
       this.Controls.Add(pBoxArray);
   }
}

Not checked the syntax, but it's something like above.

HTH
Smg.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tom KnowltonWeb developerAuthor Commented:
smegg:

Okay....we are on the right track.

Now I don't understand why only the first image   [0,0]    is showing:

public void InitPictureBoxArray()
            {
                  for(int i=0;i<10;i++)
                  {
                        for(int j=0;j<10;j++)
                        {
                              pBoxArray[i,j] = new System.Windows.Forms.PictureBox();
                              pBoxArray[i,j].Image = gw.gamePieceArray[i,j].pic_box.Image;
                              this.Controls.Add(pBoxArray[i,j]);
                        }
                  }
                  
            }
0
smeggheadCommented:
try
pBoxArray[i,j].Location=new Point(i*20,j*20);
pBoxArray[i,j].Size=new Size(20,20);
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Tom KnowltonWeb developerAuthor Commented:
Der...I forgot to set   LOCATION   of the pBoxArray items.
0
smeggheadCommented:
:-) beat you to it.
0
Tom KnowltonWeb developerAuthor Commented:
My current solution  (until I tweak it again)  L)

public void InitPictureBoxArray()
            {
                  for(int i=0;i<10;i++)
                  {
                        for(int j=0;j<10;j++)
                        {
                              pBoxArray[i,j] = new System.Windows.Forms.PictureBox();
                              pBoxArray[i,j].Image = gw.gamePieceArray[i,j].pic_box.Image;
                              pBoxArray[i,j].Location=new Point(i*32,j*32);
                              pBoxArray[i,j].Size=new Size(32,32);
                              this.Controls.Add(pBoxArray[i,j]);
                        }
                  }
                  
            }
0
Tom KnowltonWeb developerAuthor Commented:
That you did.

I have a related question....I'll ask it in just a minute.
0
Tom KnowltonWeb developerAuthor Commented:
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.