我对视觉 C# 非常陌生,我想在图片框中显示一组图像
这是我的代码:
string[] list = Directory.GetFiles(@"C:\\pictures", "*.jpg");
Image[] images = new Image[5];
for (int index = 0; index < 5; index++)
{
images[index] = Image.FromFile(list[index]);
}
当我运行它时,图片框是空白的。
我对视觉 C# 非常陌生,我想在图片框中显示一组图像
这是我的代码:
string[] list = Directory.GetFiles(@"C:\\pictures", "*.jpg");
Image[] images = new Image[5];
for (int index = 0; index < 5; index++)
{
images[index] = Image.FromFile(list[index]);
}
当我运行它时,图片框是空白的。
添加表单级变量:
private int selectedImageIndex = -1; // to store the active index in the images array
添加一个带有点击事件处理程序的按钮:
selectedImageIndex++; // increment the active index
// if the active index is equal to the image count we've gone past the end of the array, so loop back to the beginning.
if (images.Count == selectedImageIndex) { selectedImageIndex = 0; }
pictureBox.Image = images[selectedImageIndex]; // assign the selected image to the picturebox