C# 在picturebox中显示一组图像

C# 在picturebox中显示一组图像,c#,arrays,image,picturebox,C#,Arrays,Image,Picturebox,我对visual 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]); } 运行时,picturebox为空。添加表单

我对visual 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]);
}

运行时,picturebox为空。

添加表单级别变量:

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

PictureBox在代码中的任何位置都不会出现-因此,没有PictureBox会显示图像。PictureBox在哪里?可能是的副本