【问题标题】:How to use Open File Dialog to Select a Folder [duplicate]如何使用打开文件对话框选择文件夹[重复]
【发布时间】:2012-03-02 22:19:45
【问题描述】:

可能重复:
How do you configure an OpenFileDIalog to select folders?

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

对于一个更直观的示例,我正在寻找类似以下的内容(如果不完全一样):http://i44.tinypic.com/x38tx1.png

有什么想法吗?

【问题讨论】:

  • Vista IFileDialog 界面公开了这个选项。在 Windows API 代码包、CommonOpenFileDialog 类、IsFolderPicker 属性中可用。
  • @HansPassant:如果您将其添加为答案,我会投赞成票。
  • @HansPassant:你能举个例子吗?我同意 Heinzi 的观点。
  • @Demasterpl:请参阅 stackoverflow.com/a/15456640/117870 链接到 this article 以获得有效的解决方案
  • 非常感谢你hhhhhhhhhhhhhhhh你问我在找什么! :)

标签: c# openfiledialog


【解决方案1】:

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

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

  • 使用一些第三方 .NET 库(例如Ookii.Dialogs),

  • 使用相关的 Windows API 调用或

  • 使用Windows API Code Pack

      using Microsoft.WindowsAPICodePack.Dialogs;
    
      ...
    
      var dialog = new CommonOpenFileDialog(); 
      dialog.IsFolderPicker = true;
      CommonFileDialogResult result = dialog.ShowDialog();
    

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

【讨论】:

  • 3.5 中的 Winforms 和 4.0 中的 WPF 都已更新为使用 Vista 对话框。
  • @HansPassant:不。我刚试过:new FolderBrowserDialog().ShowDialog(); 在 .NET 4.0 WinForms 应用程序中显示了同样陈旧、丑陋的 FolderBrowserDialog。
  • 检查 FileDialog.AutoUpgradeEnabled 属性。
  • @HansPassant:FolderBrowserDialog 不是从FileDialog 派生的。因此,它缺少此属性(及其功能)。
  • 我希望我可以发布一个示例,但问题已关闭。在我看来,这与上面列出的可能重复的问题完全不同。
猜你喜欢
  • 1970-01-01
  • 2011-04-25
  • 2018-01-12
  • 2020-11-24
  • 2012-10-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多