I am making a simple app which will show the images from a specific folder on a winform load. I've done the "showing part" with using openfileDialog and it's working fine, where the user has to select images each time.I want to make it more automatic that user doesn't have to select the files, It should select the files automatically.
Target Folder is static(It'll remain same) while it contains multiple images. How can I obtain all of the image files from the directory?
I am using this code.
string[] path = Directory.GetFiles("Cards");
foreach (string filepath in path)
{
string[] files = filepath;
int x = 20;
int y = 20;
int maxheight = -1;
foreach (string img in files)
{
PictureBox pic = new PictureBox();
pic.Image = Image.FromFile(img);
pic.Location = new Point(x, y);
pic.Size = new Size(200, 200);
pic.SizeMode = PictureBoxSizeMode.Zoom;
x += pic.Width + 10;
maxheight = Math.Max(pic.Height, maxheight);
if (x > this.ClientSize.Width - 100)
{
x = 20;
y += maxheight + 10;
}
this.panelImages.Controls.Add(pic);
}
}
but stuck at string[] files = filepath; here.
Please guide me where I am making any mistake.
Please let me know if anybody needs more info.
Thanks in advance.