使用打开文件对话框的目录,而不是的FolderBrowserDialog [英] using OpenFileDialog for directory, not FolderBrowserDialog
问题描述
我想有一个文件夹的浏览器在我的应用程序,但我不要使用的FolderBrowserDialog。 (由于多种原因,比如它是痛苦的使用)
I want to have a Folder browser in my application, but I don't want to use the FolderBrowserDialog. (For several reasons, such as it's painful to use)
我要使用标准的OpenFileDialog,但修改的目录。
I want to use the standard OpenFileDialog, but modified for the directories.
作为一个例子,的μTorrent有一个很好的实现它(偏好/目录/提出了新的下载量:)。标准的打开文件对话框让用户:
As an example, µTorrent has a nice implementation of it (Preferences/Directories/Put new downloads in:). The standard Open File Dialog enable the user to:
- 粘贴在底部
- 使用在Vista收藏夹链接栏
- 在Vista中使用搜索
- 汽车还记得去年目录
- 更多...
在文本字段中完整路径
- paste full paths in the text field at bottom
- use "Favorite Links" bar on Vista
- use Search on Vista
- auto remember last directory
- more...
有谁知道如何实现这一点?在C#
Does anybody know how to implement this? In C#.
推荐答案
我不知道uTorrent的,但是这听起来很像Vista新的的 IFileDialog 与FOS_PICKFOLDERS选项集。通用的C#代码,它会去是这样的:
I am not sure about uTorrent but this sounds pretty much like new Vista's IFileDialog with FOS_PICKFOLDERS option set. Generic C# code for it would go something like:
var frm = (IFileDialog)(new FileOpenDialogRCW());
uint options;
frm.GetOptions(out options);
options |= FOS_PICKFOLDERS;
frm.SetOptions(options);
if (frm.Show(owner.Handle) == S_OK) {
IShellItem shellItem;
frm.GetResult(out shellItem);
IntPtr pszString;
shellItem.GetDisplayName(SIGDN_FILESYSPATH, out pszString);
this.Folder = Marshal.PtrToStringAuto(pszString);
}
的完整代码,可以发现的这里。
这篇关于使用打开文件对话框的目录,而不是的FolderBrowserDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!