添加一个BUTTON, ComboBox, FolderBrowserDialg1.
Code:
private void btnShowFile_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbdSetFolder = new FolderBrowserDialog();
if (fbdSetFolder.ShowDialog() == DialogResult.OK)
{
DirectoryInfo dirFileFolder = new DirectoryInfo(fbdSetFolder.SelectedPath);
if (!dirFileFolder.Exists)
{
return;
}
FileInfo[] fi = dirFileFolder.GetFiles();
foreach (FileInfo file in fi)
{
cmbShowFile.Items.Add(file);
}
}
}
运行结果如下: