如何使用打开文件对话框选择一个文件夹 [英] How to use Open File Dialog to Select a Folder
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/31059/how-do-you-configure-an-openfiledialog-to-select-folders\">How你配置一个OpenFileDialog选择文件夹?
我使用C#,我想完全避免SelectFolderDialog选择一个文件夹。相反,我想使用的东西更接近的OpenFileDialog只是选择一个文件夹。
I'm using C# and I want to completely avoid SelectFolderDialog to select a folder. Instead, I want to use something closer to a OpenFileDialog just to select a folder.
有关更直观的例子,我在找一个接近(如果不是完全)像下面这样:的http:// I44 .tinypic.com / x38tx1.png
For a more visual example, I'm looking for something close (if not exactly) like the following: http://i44.tinypic.com/x38tx1.png
任何想法?
推荐答案
Windows Vista中的文件夹选择对话框看起来非常相似,你想要什么。不幸的是,.NET的的FolderBrowserDialog
显示旧的Windows-XP一样对话框,你希望避免的。
The folder selection dialog of Windows Vista looks quite similar to what you want. Unfortunately, .NET's FolderBrowserDialog
shows the old Windows-XP-like dialog, which you want to avoid.
要访问此Vista风格对话框,您可以
To access this Vista-style dialog, you can either
- 使用一些第三方.NET库(例如 Ookii.Dialogs )
- 使用相关的Windows API调用或
using Microsoft.WindowsAPICodePack.Dialogs;
...
var dialog = new CommonOpenFileDialog();
dialog.IsFolderPicker = true;
CommonFileDialogResult result = dialog.ShowDialog();
请注意,这个对话框是不可比的Windows Vista旧的操作系统,所以一定要检查 CommonFileDialog.IsPlatformSupported
第一。
Note that this dialog is not available on operating systems older than Windows Vista, so be sure to check CommonFileDialog.IsPlatformSupported
first.
这篇关于如何使用打开文件对话框选择一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!