选择一:在.NET同一对话框的文件或文件夹 [英] Select either a file or folder from the same dialog in .NET

查看:144
本文介绍了选择一:在.NET同一对话框的文件或文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个简单的方式来选择一个文件或从同一个对话框中的文件夹?

Is there an "easy" way to select either a file OR a folder from the same dialog?

在我创造我允许两个文件或文件夹作为输入许多应用程序。 直到现在我总是最终创建一个开关,文件或文件夹选择对话框之间切换,或坚持只拖和拖放功能。

In many apps I create I allow for both files or folders as input. Until now i always end up creating a switch to toggle between file or folder selection dialogs or stick with drag-and-drop functionality only.

由于这似乎是这样一个基本的东西,我会想象这之前已经建立,但谷歌搜索不会导致太多的信息。所以它看起来像我需要从头开始,并创建一个自定义选择对话框,但我宁愿不重新发明轮子对于这样一个简单的任务提出的任何问题。

Since this seems such a basic thing i would imagine this has been created before, but googling does not result in much information. So it looks like i would need to start from scratch and create a custom selection Dialog, but I rather not introduce any problems by reinventing the wheel for such a trivial task.

任何人任何提示或现有的解决方案?

Anybody any tips or existing solutions?

要保持一致的用户界面将是很好,如果有可能延长的OpenFileDialog(或的FolderBrowserDialog)。

To keep the UI consistent it would be nice if it is possible to extend the OpenFileDialog (or the FolderBrowserDialog).

推荐答案

从技术上讲,这是可能的。使用FolderBrowseDialog外壳对话框必须返回文件和文件夹的能力。不幸的是,该功能不会显示在.NET。甚至不反射可捅所需的选项标志。

Technically, it is possible. The shell dialog used by FolderBrowseDialog has the ability to return both files and folders. Unfortunately, that capability isn't exposed in .NET. Not even reflection can poke the required option flag.

要使它工作,你必须的P / Invoke的SHBrowseForFolder()与BIF_BROWSEINCLUDEFILES标志BROWSEINFO.ulFlags开启(值= 0x4000的)。在P / Invoke的是坚韧不拔的,最好是复制和粘贴从code <一个href="http://www.google.com/search?hl=en&q=shbrowseforfolder+structlayout&btnG=Google+Search&aq=f&oq=">another来源或FolderBrowseDialog类本身与反射器的帮助。

To make it work, you'd have to P/Invoke SHBrowseForFolder() with the BIF_BROWSEINCLUDEFILES flag turned on in BROWSEINFO.ulFlags (value = 0x4000). The P/Invoke is gritty, it is best to copy and paste the code from another source or the FolderBrowseDialog class itself with Reflector's help.

这篇关于选择一:在.NET同一对话框的文件或文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆