C# FolderBrowser对话框嵌套文件夹

C# FolderBrowser对话框嵌套文件夹,c#,folderbrowserdialog,C#,Folderbrowserdialog,我有一个文件夹。文件夹中有多个文件夹,每个文件夹中都有一个图像。像这样: Main Folder>Subfolder 1>Picture 1 Main Folder>Subfolder 2>Picture 2 等等 我希望使用FolderBrowserDialog选择主文件夹,并以某种方式显示子文件夹中的所有图片(图片1、图片2等)。使用FolderBrowserDialog可以这样做吗?如果不可以,我该怎么做?谢谢是的,这是可能的,但是FolderBrowser对话

我有一个文件夹。文件夹中有多个文件夹,每个文件夹中都有一个图像。像这样:

Main Folder>Subfolder 1>Picture 1

Main Folder>Subfolder 2>Picture 2
等等


我希望使用
FolderBrowserDialog
选择主文件夹,并以某种方式显示子文件夹中的所有图片(图片1、图片2等)。使用
FolderBrowserDialog可以这样做吗?
如果不可以,我该怎么做?谢谢

是的,这是可能的,但是
FolderBrowser对话框
只是解决方案的一部分。它可能看起来像这样:

Directory.GetFiles("path", "*.jpeg", SearchOption.AllDirectories);
using (var fbd = new FolderBrowserDialog())
{
    if (fbd.ShowDialog() == DialogResult.OK)
    {
        foreach (var file in Directory.GetFiles(fbd.SelectedPath,
            "*.png", SearchOption.AllDirectories)
        {
            // this catches things like *.png1 or *.pngp
            // not that they'd ever exist; but they may
            if (Path.GetExtension(file).Length > 4) { continue; }

            var pictureBox = new PictureBox();
            pictureBox.Load(file);

            // set its location here

            this.Controls.Add(pictureBox);
        }
    }
}
这段代码只搜索
png
文件,值得注意的是,我之所以检查扩展名,是因为在3字符扩展名搜索中有一个鲜为人知的警告:

文件扩展名正好为三个字符的searchPattern返回扩展名为三个或更多字符的文件,其中前三个字符与searchPattern中指定的文件扩展名匹配


使用文件夹浏览器对话框,用户只能选择文件夹,不能选择文件。因此,您可以自己控制显示选定文件夹中存在的图像列表

        FolderBrowserDialog folderBrowserDlg = new FolderBrowserDialog();
        DialogResult dlgResult = folderBrowserDlg.ShowDialog();
        if (dlgResult.Equals(DialogResult.OK))
        {
            foreach (string file in System.IO.Directory.GetFiles(folderBrowserDlg.SelectedPath, "*.png")) //.png, bmp, etc.
            {
                Image image = new Bitmap(file);
                imageList1.Images.Add(image);                 
            }
        }

        this.listView1.View = View.LargeIcon;
        this.imageList1.ImageSize = new Size(32, 32);
        this.listView1.LargeImageList = this.imageList1;
        for (int j = 0; j < this.imageList1.Images.Count; j++)
        {
            ListViewItem item = new ListViewItem();
            item.ImageIndex = j;
            this.listView1.Items.Add(item);
        }
FolderBrowserDialog folderBrowserDlg=新建FolderBrowserDialog();
DialogResult dlgResult=folderBrowserDlg.ShowDialog();
if(dlgResult.Equals(DialogResult.OK))
{
foreach(System.IO.Directory.GetFiles中的字符串文件(folderBrowserDlg.SelectedPath,“*.png”)//png、bmp等。
{
图像=新位图(文件);
imageList1.Images.Add(图像);
}
}
this.listView1.View=View.LargeIcon;
this.imageList1.ImageSize=新大小(32,32);
this.listView1.LargeImageList=this.imageList1;
对于(int j=0;j
上面的代码将获取所选文件夹中存在的图像文件列表,并将它们添加到listview控件中

你是说:。您提供的链接是针对.NET Micro Framework的。