开发者

Restricted FolderBrowserDialog, recommended solution

开发者 https://www.devze.com 2023-03-17 17:29 出处:网络
We want to prevent th开发者_如何学运维e 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\'

We want to prevent th开发者_如何学运维e 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


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.


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号