我的视图中有两个按钮和一个图片框。我想设计一个代码,使图片框在目录中显示图像,点击两个按钮之一后,它会显示下一个图像。基本上,它应该等待用户单击按钮。
这是示例代码。请帮帮我。
foreach (string file in Directory.EnumerateFiles(sourcePathImages, "*.jpg"))
{
Image loadedImage = new Bitmap(file);
if (loadedImage != null)
{
pictureBox1.Image = loadedImage;
filename.Text = filenames[counter];
label.Text = labels[counter++];
}
}
在foreach循环中添加什么,以便我的代码等到按下两个按钮之一。
答案 0 :(得分:0)
您可以将Directory.EnumerateFiles转换为List并保留当前图像名称的索引。
或者您可以使用GetFiles()
方法获取名称数组。