【发布时间】:2017-07-13 11:50:15
【问题描述】:
我正在尝试从我使用 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);
标签: c# arrays picturebox