1

私はビジュアル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]);
}

実行すると、ピクチャボックスが空白になります。

4

1 に答える 1

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
于 2012-08-08T17:29:38.620 に答える