我想從使用Directory.GetFiles()創建的圖片的字符串數組中加載圖片到圖片框中。我相信我沒有正確設置picFile的設置。嘗試從圖片數組中加載圖片
我已經不是創造了一個pictureBox_Click事件後續加載圖片,但如果我重定向字符串數組到控制檯我看到在該目錄中的文件列表中沒有寫該事件處理
string fileEntries = "";
private void showButton_Click(object sender, EventArgs e)
{
// First I want the user to be able to browse to and select a
// folder that the user wants to view pictures in
string folderPath = "";
FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
folderPath = folderBrowserDialog1.SelectedPath;
}
// Now I want to read all of the files of a given type into a
// array that from the path provided above
ProcessDirectory(folderPath);
// after getting the list of path//filenames I want to load the first image here
string picFile = fileEntries;
pictureBox1.Load(picFile);
}
public static void ProcessDirectory(string targetDirectoy)
{
// Process the list of files found in the directory.
string[] fileEntries = Directory.GetFiles(targetDirectoy);
}
// event handler here that advances to the next picture in the list
// upon clicking
}
但也有完整的路徑作爲字符串的一部分 - 不知道這是否是問題。
嘗試pictureBox1.Image = Image.FromFile(picFile); –