在picturebox中显示图像数组

时间:2012-08-08 15:46:47

标签: c# arrays image picturebox

我是视觉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]);
}

当我运行它时,图片框是空白的。

1 个答案:

答案 0 :(得分:0)

添加表单级变量:

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