简体   繁体   English

在c#winforms应用程序中显示窗口(文件/目录)上下文菜单

[英]Showing windows (file/directory) context menu in c# winforms application

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. 我正在尝试在WinForms应用程序中显示标准文件/目录上下文菜单 - 我想让用户在我的应用程序中使用资源管理器中的文件。

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 谢谢

I have written a .NET library to allow this. 我写了一个.NET库来实现这个目的。 You can find it here: 你可以在这里找到它:

http://gong-shell.sourceforge.net/ http://gong-shell.sourceforge.net/

The class you're looking for is ShellContextMenu within that library. 您正在寻找的类是该库中的ShellContextMenu。

This may prove to be very challenging, so I propose two solutions: 这可能证明是非常具有挑战性的,所以我提出了两个解决方案:

  1. (Easy) Using the library that Groky suggested, do what is done in FolderSizes . (简单)使用Groky建议的库, 执行在FolderSizes中完成的操作。 The Explorer context menu is shown as a sub-context-menu. Explorer上下文菜单显示为子上下文菜单。 You can simulate this by displaying the explorer menu when the "Explorer Operation" item is hovered. 您可以通过在“资源管理器操作”项目悬停时显示资源管理器菜单来模拟此项。

    在此输入图像描述

  2. (Hard) If that is insufficient, you can go all the way and get the menu items from the shell, and create your own menu. (硬)如果不够,你可以一直走到shell中获取菜单项,然后创建自己的菜单。 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. 此CodeProject文章( http://www.codeproject.com/KB/miscctrl/FileBrowser.aspx )将完成枚举和调用特定shell对象的shell命令以及如何枚举子菜单的过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM