在 C# winforms 应用程序中显示窗口(文件/目录)上下文菜单
我正在尝试在 WinForms 应用程序中显示标准文件/目录上下文菜单 - 我想让用户能够像在资源管理器中一样对我的应用程序中的文件执行操作。
应该有两个选项
- 上下文菜单中
- 弹出,其中一些系统调用从系统上下文菜单中读取所有内容并将其插入到我的上下文菜单中,
您能指出我正确的方向吗?谢谢
I'm trying to display standard file/directory context menu in WinForms application - I'd like to enable the user to do things with files in my application as he could in Explorer.
There should be two options
- popup the context menu with some system call
- read everything from the system context menu and insert it into my context menu
Could you please point me in the right direction? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经编写了一个 .NET 库来实现这一点。您可以在这里找到它:
http://gong-shell.sourceforge.net/
您的课程正在寻找的是该库中的 ShellContextMenu。
I have written a .NET library to allow this. You can find it here:
http://gong-shell.sourceforge.net/
The class you're looking for is ShellContextMenu within that library.
这可能被证明是非常具有挑战性的,所以我提出了两种解决方案:
(简单)使用 Groky 建议的库,执行 FolderSizes。 资源管理器上下文菜单显示为子上下文菜单。您可以通过在“资源管理器操作”项悬停时显示资源管理器菜单来模拟这一点。
(困难) 如果这还不够,您可以一路走下去,从 shell 中获取菜单项,并创建您自己的菜单。这篇 CodeProject 文章 ( http://www.codeproject.com/KB/miscctrl/FileBrowser.aspx )详细介绍了为特定 shell 对象枚举和调用 shell 命令的过程,以及如何枚举子菜单。
This may prove to be very challenging, so I propose two solutions:
(Easy) Using the library that Groky suggested, do what is done in FolderSizes. The Explorer context menu is shown as a sub-context-menu. You can simulate this by displaying the explorer menu when the "Explorer Operation" item is hovered.
(Hard) If that is insufficient, you can go all the way and get the menu items from the shell, and create your own menu. This CodeProject article ( http://www.codeproject.com/KB/miscctrl/FileBrowser.aspx ) goes through the process of enumerating and invoking shell commands for a specific shell object, and how to enumerate submenus.