デバッグディレクトリ内にあるすべての画像を表示したい。また、ラベルとしてのファイル名。
私の唯一の問題は、各画像のパスからファイル名を表示することです。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;
}