Restricted FolderBrowserDialog, recommended solution

我与影子孤独终老i 提交于 2019-12-06 10:54:57

问题


We want to prevent the user from doing anything except selecting a folder. We don't want to allow him to delete files/folders, rename them, access the context menu, etc. But we can't override anything since FolderBrowserDialog is sealed.

We googled around and found some solutions:

  • Implement our own FolderBrowserDialog: Don't have time for this, only acceptable as last resort
  • This guy did it for an OpenFileDialog, might work but seems a little overkill

Anyone faced this problem and found an optimal solution for this? It must be .NET 4.0 compatible


回答1:


You best bet is to use a control like FolderView from Shell MegaPack - it is customizable in the way you want it - you can turn of shell context menus, renaming, drag-drop, keyboard shortcuts, etc,

DISCLAIMER: We are the developers of FolderView mentioned above.




回答2:


In the end, we solved it implementing our own control. It was a lot simpler than we thought. In short, we just made a class inherit from System.Windows.Forms.Form, with a System.Windows.Forms.TreeView on the left and a System.Windows.Forms.ImageList on the right to show the current folder's contents. Then we DllImport'ed SHGetFileInfo and ExtractIconEx from Shell32 in order to make the TreeView and ImageList's icons look like Explorer's, and voila!



来源:https://stackoverflow.com/questions/6588229/restricted-folderbrowserdialog-recommended-solution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!