Link to home
Start Free TrialLog in
Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on

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?
ASKER CERTIFIED SOLUTION
Avatar of smegghead
smegghead
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tom Knowlton

ASKER

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]);
                        }
                  }
                  
            }
try
pBoxArray[i,j].Location=new Point(i*20,j*20);
pBoxArray[i,j].Size=new Size(20,20);
Der...I forgot to set   LOCATION   of the pBoxArray items.
:-) beat you to it.
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]);
                        }
                  }
                  
            }
That you did.

I have a related question....I'll ask it in just a minute.