views:

153

answers:

2

I'm unable to make my pictureboxes to be shown on form. Am i doing it wrong or? This is my code:

static Bitmap[] pictures = new Bitmap[9];
PictureBox[] picBox= new PictureBox[9];

on the constructor :

            pictures[1] = new Bitmap(@"1.1Bright.jpg");

         *  picBox[1].Location = new System.Drawing.Point(25, 7);
            picBox[1].SizeMode = PictureBoxSizeMode.StretchImage;
            picBox[1].ClientSize = new Size(53, 40);
            picBox[1].Image = pictures[1];

I keep getting nullreferenceexception error on *

+2  A: 

You haven't set picBox[1] to reference anything. You need something like:

picBox[1] = new PictureBox();

Do you really want the pictures variable to be static though? The array contents will be overwritten every time you create an instance of the form...

Jon Skeet
A: 

got it:

picBox[0] = new PictureBox();   
this.Controls.Add(this.picBox[0]);
cheesebunz