I know pictureBox only lets you display one image a time. I’m trying to create a pictureBox for each image in my collection. For instance if I have ten images in my List, then the method should create ten pictureBox for those respective images so each one is displayes in a pictureBox. I’m not sure which would be better a for loop or a foreach loop instead. every time the loop increments both the varaiables XCoordinate and YCoordinate which are the location of the PictireBox shoulld increase so that the PictureBox won’t overlap one another in the Form. The reason for the method is that the number of images in the collection can change everytime the application will run. That’s why I’m not creating them manually. So after its done all the pictures in the list should appear in a picture.Box. The box should be all the same size the only difference is the location on the form and the images inside themmaking multiple pictureBoxes. Please any help and I will be grateful
what is should look like http://imageshack.us/photo/my-images/41/59536200.png/ Heres Thanks for the code that I’m working onsoltion big help.
public List<Image> returnImagesInList()
{
return this.images;
}
private void createPictureBoxesForImages()
{
foreach (Image file in retrurnImagesInList())
{
try
{
int XCoordinate = 10;
XCoordinate++;
int YCoordinate = 5;
YCoordinate++;
PictureBox imageControl = new PictureBox();
imageControl.Height = 100;
imageControl.Width = 100;
imageControl.Visible = true;
imageControl.Location = new Point(XCoordinate, YCoordinate);
Controls.Add(imageControl);
imageControl.Image = file;
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
}
You are incrementing only one in x and y coordinates for each picturebox and its should be greater or equal to width and height of pictureobx. You initialize the coordinates with same value in the iteration and brings you back to where you started.
You need to take initialization out side loop and give larger increment larger then width. You have to increment y coordinates when the picturebox reaches right end of form.