現在、ディレクトリを調べて .jpg ファイルを見つけ、結果をリストボックスに表示しようとしています。それが終わったら、画像を選択してピクチャボックスに表示したいと思います。
これは私が持っているコードです:
private void Form1_load(object sender, EventArgs e)
{
string filepath = "F:\\Apps Development\\Coursework\\3_Coursework\\3_Coursework\\bin\\Debug\\Pics";
DirectoryInfo dirinfo = new DirectoryInfo(filepath);
FileInfo[] images = dirinfo.GetFiles("*.jpg");
foreach (FileInfo image in images)
{
lstImages.Items.Add(image.Name);
}
}
private void lstImages_SelectedIndexChanged(object sender, EventArgs e)
{
string filepath = "F:\\Apps Development\\Coursework\\3_Coursework\\3_Coursework\\bin\\Debug\\Pics";
pictureBox1.ImageLocation = filepath + lstImages.SelectedItem.ToString();
pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
}
これはうまくいくように見えます。しかし、それは私が望むものをリストに入力しません。何か案は?