I created 100 pictures boxes for my game with this code :
for (int p = 0; p <= 9; p++)
{
for (int o = 0; o <= 9; o++)
{
picsBoard[p, o] = new PictureBox();
picsBoard[p, o].Name = "emptyPicBox" + p.ToString() + "." + o.ToString();
picsBoard[p, o].Location = new Point(40 + locCountX, 38 + locCountY);
picsBoard[p, o].Size = new Size(32, 36);
picsBoard[p, o].BackColor = System.Drawing.Color.Transparent;
picsBoard[p, o].BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
picsBoard[p, o].Visible = true;
this.Controls.Add(picsBoard[p, o]);
locCountX += 43;
picsBoard[p, o].BringToFront();
}
locCountY += 43;
locCountX = 0;
}
then, I want to change the Image in every pB from another form, thats why I wrote this code :
public void SetImage(Image img)
{
picsBoard[this.i, this.j].Image = img;
}
and im using it from Form2 :
frm1.SetImage(Properties.Resources.b1);
Hide();
but when I trying this thing all the pictureBoxes I created simply becoming 'null' again :\
and it gives the error :
Object reference not set to an instance of an object.