Reputation: 425
I created an array of PictureBox
objects in my code like so:
PictureBox[] picturbox = new PictureBox[100];
Then I have this in Form's load code:
picturbox[1] = new PictureBox();
picturbox[1].Image = Properties.Resources.img1;
picturbox[1].Visible = true;
picturbox[1].Location = new Point(0, 0);
this.Size = new Size(800, 600);
picturbox[1].Size = new Size(800, 600);
However, the PictureBox
does not appear on the Form. When I do exact same command with PictureBox
that was created by Drag & Drop, it works just fine.
Upvotes: 0
Views: 6038
Reputation: 13
This works just as well:
this.Controls.AddRange(picturebox);
For a collection that isn't an array use this:
this.Controls.AddRange(picturebox.ToArray());
Upvotes: 0
Reputation: 29
If you did not add picture box, check the InitializeComponent();
method. It is positioned at the top of the code.
Upvotes: 0
Reputation: 35477
You need to add each PictureBox to the form's Controls.
foreach(var box in picturbox)
this.Controls.Add(box)
Upvotes: 2
Reputation: 47978
You need to add the pictureBox to the Form:
this.Controls.Add(picturebox[1]);
Upvotes: 2