加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何在OpenFileDialog窗口中隐藏功能和可选文件夹/驱动器

发布时间:2020-12-15 21:47:37 所属栏目:百科 来源:网络整理
导读:我目前正在为运行WES7的嵌入式设备开发软件.该应用程序是一个标准的.NET 3.5 WinForms项目. 要求是用户应该能够从他们的pendrive或网络中浏览和选择特定文件,而不能从系统驱动器上的任何位置浏览和选择特定文件.所以我正在寻找一种解决方案,以某种方式隐藏标
我目前正在为运行WES7的嵌入式设备开发软件.该应用程序是一个标准的.NET 3.5 WinForms项目.

要求是用户应该能够从他们的pendrive或网络中浏览和选择特定文件,而不能从系统驱动器上的任何位置浏览和选择特定文件.所以我正在寻找一种解决方案,以某种方式隐藏标准OpenFileDialog窗口上的链接和按钮,因此如果有任何网络位置链接,用户只会看到他们的pendrives.

我也在MSDN和其他论坛上搜索过,直到现在我才发现任何想法.如果没有办法使用标准的OpenFileDialog工作,是否有任何简单的自定义组件用于浏览限制在指定驱动器或父文件夹的文件?

解决方法

在这里,它就像 Customizing Your Open File Dialog一样简单

The OpenFileDialog class exposes a set of properties to configure the
dialog. For example,you can choose the initial directory,the initial
filter index,the title of the window,whether multiple files can be
selected,and whether the application’s current directory should be
restored before closing. The class also fires an event (called FileOk)
whenever the user clicks on the Open button.

OpenFileDialog is a sealed class,so you can’t derive from it.
However,if you want to customize the behavior of a file dialog,to
the extent that it is possible,you should create a brand new class
deriving from the abstract class FileDialog. In this case,you have
access to a couple of powerful but protected methods such as HookProc
and RunDialog. HookProc defines the dialog box hook procedure that
adds specific functionality to the common dialog….

更新:

在Windows 7 PC上它不起作用.例如:

OpenDialogPlaces o = new OpenDialogPlaces();
//o.Places.Add(18);
//o.Places.Add(5);
//o.Places.Add(6);
o.Init();
o.OpenDialog.ShowDialog();
o.Reset();

仍然显示左手的一切:

它在以前的Windows版本中有效:

另一件事似乎是微软已经改变了ComDlg32的位置,我尝试了两个地方但没有运气.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读