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 = Pr开发者_运维知识库operties.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.
You need to add the pictureBox to the Form:
this.Controls.Add(picturebox[1]);
You need to add each PictureBox to the form's Controls.
foreach(var box in picturbox)
this.Controls.Add(box)
If you did not add picture box, check the InitializeComponent();
method. It is positioned at the top of the code.
This works just as well:
this.Controls.AddRange(picturebox);
For a collection that isn't an array use this:
this.Controls.AddRange(picturebox.ToArray());
精彩评论