如何使用"打开文件"对话框选择文件夹

Dem*_*rpl 21 c# openfiledialog

可能重复:
如何配置OpenFileDIalog以选择文件夹?

我正在使用C#,我想完全避免使用SelectFolderDialog来选择文件夹.相反,我想使用更接近OpenFileDialog的东西来选择一个文件夹.

有关更直观的示例,我正在寻找与以下内容非常接近的内容:http://i44.tinypic.com/x38tx1.png

在此输入图像描述

有任何想法吗?

Hei*_*nzi 29

Windows Vista的文件夹选择对话框看起来非常类似于您想要的.不幸的是,.NET FolderBrowserDialog显示了你想要避免的类似Windows-XP的旧对话框.

要访问此Vista风格的对话框,您可以

  • 使用一些第三方.NET库(例如Ookii.Dialogs),
  • 使用相关的Windows API调用或
  • 使用Windows API代码包:

    using Microsoft.WindowsAPICodePack.Dialogs;
    
    ...
    
    var dialog = new CommonOpenFileDialog(); 
    dialog.IsFolderPicker = true;
    CommonFileDialogResult result = dialog.ShowDialog();
    
    Run Code Online (Sandbox Code Playgroud)

    请注意,此对话框在Windows Vista之前的操作系统上不可用,因此请务必先检查CommonFileDialog.IsPlatformSupported.

  • 我希望我能发一个例子,但问题已经结束了.在我看来,这是一个完全不同的问题,而不是上面列出的可能重复. (4认同)
  • 3.5中的Winforms和4.0中的WPF都已更新为使用Vista对话框. (2认同)