我想显示调试目录中的所有图像。也将文件名作为标签。
我唯一的问题是从每个图像的路径中显示文件名。它仅加载 1 个文件名
int x = 0;
int y = 0;
string[] images = Directory.GetFiles(@"images");
foreach (string image in images)
{
PictureBox PB = new PictureBox();
PB.Image = new Bitmap(image);
PB.SizeMode = PictureBoxSizeMode.CenterImage;
PB.Size = new Size(250, 180);
PB.Location = new Point(x, y);
panel1.Controls.Add(PB);
x += 260;
}
int a = 0;
int b = 0;
string names = System.IO.Path.GetFileName(@"images");
foreach (string name in names)
{
Label label1 = new Label();
label1.Text = name;
label1.Location = new Point(a, b);
this.Controls.Add(label1);
a += 20;
}