如何从 C# 应用程序显示 Windows 资源管理器上下文菜单?

发布于 2024-07-11 05:36:16 字数 99 浏览 7 评论 0原文

我的应用程序中有一个文件列表,我希望允许人们右键单击某个项目并显示 Windows 资源管理器上下文菜单。 我假设我需要使用 IContextMenu 接口,但我不太确定从哪里开始。

I have a file listing in my application and I would like to allow people to right-click on an item and show the Windows Explorer context menu. I'm assuming I would need to use the IContextMenu interface, but I'm not really sure where to start.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

千里故人稀 2024-07-18 05:36:16

我写了一个库,也许可以帮助你。 您可以使用库提供的控件,或者如果您不想这样做,查看代码可能会给您答案。

您可以在以下位置找到该库: http://gong-shell.sourceforge.net/

请让我知道这是否有帮助!

I have written a library that might be able to help you. You could use the controls provided by the library, or if you don't want to do that, looking through the code may give you an answer.

You can find the library at: http://gong-shell.sourceforge.net/

Please let me know if this helped!

最佳男配角 2024-07-18 05:36:16

我发现了一篇很棒的代码项目文章,它将所有内容很好地封装到一个类中!

Explorer Shell 上下文菜单

就像下面的代码片段一样简单:

// Sample code

ShellContextMenu ctxMnu = new ShellContextMenu();
FileInfo[] arrFI = new FileInfo[1];
arrFI[0] = new FileInfo(this.treeMain.SelectedNode.Tag.ToString());
ctxMnu.ShowContextMenu(arrFI, this.PointToScreen(new Point(e.X, e.Y)));

唯一令人厌烦的事情是它需要一个 FileInfo[] 数组或一个 DirectoryInfo[] 数组,尽管很容易稍微修改源代码,以便它需要一个 FileSystemInfo[] 数组

I found a great Code Project article that encapsulates everything very nicely into one class!

Explorer Shell Context Menu

It's as easy as the following code snippet:

// Sample code

ShellContextMenu ctxMnu = new ShellContextMenu();
FileInfo[] arrFI = new FileInfo[1];
arrFI[0] = new FileInfo(this.treeMain.SelectedNode.Tag.ToString());
ctxMnu.ShowContextMenu(arrFI, this.PointToScreen(new Point(e.X, e.Y)));

The only irksome thing is that it takes either an array of FileInfo[] or an array of DirectoryInfo[] although it was VERY easy to modify the source slightly so that it would take an array of FileSystemInfo[]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文