[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

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?
0
Tom Knowlton
Asked:
Tom Knowlton
  • 5
  • 3
1 Solution
 
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
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now