picture box - help!!
-
How to display all the image files in a directory? Even with the for loop below, I only get one image file displayed. I don't know if the problem lies in the location of the picturebox1. Can anyone please help? int y = 5; foreach (String file in files) { if (file.Contains(".jpg")) { System.Windows.Forms.PictureBox pictureBox1 = new System.Windows.Forms.PictureBox(); picture.Controls.Add(pictureBox1); pictureBox1.ImageLocation = file; pictureBox1.Location = new System.Drawing.Point(6, y); pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; y = y + pictureBox1.Size.Height + 5; } }
-
How to display all the image files in a directory? Even with the for loop below, I only get one image file displayed. I don't know if the problem lies in the location of the picturebox1. Can anyone please help? int y = 5; foreach (String file in files) { if (file.Contains(".jpg")) { System.Windows.Forms.PictureBox pictureBox1 = new System.Windows.Forms.PictureBox(); picture.Controls.Add(pictureBox1); pictureBox1.ImageLocation = file; pictureBox1.Location = new System.Drawing.Point(6, y); pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; y = y + pictureBox1.Size.Height + 5; } }
Hi, I can't see anything wrong with the code above. What control is
picture
? I'm assuming it's a panel or something. Might be handy to post the code used to gain the list of files. -
How to display all the image files in a directory? Even with the for loop below, I only get one image file displayed. I don't know if the problem lies in the location of the picturebox1. Can anyone please help? int y = 5; foreach (String file in files) { if (file.Contains(".jpg")) { System.Windows.Forms.PictureBox pictureBox1 = new System.Windows.Forms.PictureBox(); picture.Controls.Add(pictureBox1); pictureBox1.ImageLocation = file; pictureBox1.Location = new System.Drawing.Point(6, y); pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; y = y + pictureBox1.Size.Height + 5; } }
Do you mean you get just one PictureBox with one image, or many PictureBoxes all with the same image?
-
Hi, I can't see anything wrong with the code above. What control is
picture
? I'm assuming it's a panel or something. Might be handy to post the code used to gain the list of files.It's a tabpage control. I debug it through and found that the size of the picture box has not changed to the size of the picture (I guess this is what it should be by using autosize mode). From this I would assume the new picture box is added on top of the existing one with exactly the same size each time.....
-
Do you mean you get just one PictureBox with one image, or many PictureBoxes all with the same image?
It seems to me that the new picture box is added on top of the existing one with exactly the same size each time. That's why I only see one image. Setting the sizemode to autosize doesn't change the size of the picture box??
-
It seems to me that the new picture box is added on top of the existing one with exactly the same size each time. That's why I only see one image. Setting the sizemode to autosize doesn't change the size of the picture box??
Hello If I were you I'd use a foreach loop to check the parent.Controls for the next: 1- Make sure that the pictureboxes are all added up tto the parent successfully 2- Make sure of the ImageLocation property of each Picturebox 3- The size and location of each picturebox This may clarify the problem. If it's like you said, simply calculate the size manually each time by calculating the image's size -ie. don't rely on AutoSize" Happy programming;)