gpt4 book ai didi

c# - 无法使用 C# 在 shell 扩展中添加图标

转载 作者:行者123 更新时间:2023-11-30 14:59:49 25 4
gpt4 key购买 nike

我找到了一个非常好的教程,我正在尝试了解本教程中没有的内容(因为 tut 本身工作正常) http://www.codeproject.com/Articles/9163/File-Rating-a-practical-example-of-shell-extension

当您查看 WinRar、TortoiseSVN、Antivirus-apps 等应用程序时,Shell 扩展项旁边有一个图标。

我想知道这是怎么做到的。 (使用 C# 以编程方式)

添加分隔符有效,添加子菜单有效,点击+操作也有效,但我在图标上苦苦挣扎。这不可能那么难。有人可以帮助我吗?

并且请不要说 Microsoft 在 .NET 4.0 中不再支持此功能,因为无法保证,因此他们不提供示例代码。如果所有其他应用都可以做到,那么就有可能。

请提供一些示例代码、一些教程或者甚至是一段工作代码。

最佳答案

请查看以下文章,它使用 .NET 4.0 创建 Windows Shell 扩展,使用 SharpShell nuget 包。

NET Shell Extensions - Shell Context Menus

使用这个库,您可以在创建上下文菜单条时直接设置图像,如下所示

protected override ContextMenuStrip CreateMenu()
{
// Create the menu strip.
var menu = new ContextMenuStrip();

// Create a 'count lines' item.
var itemCountLines = new ToolStripMenuItem
{
Text = "Count Lines...",
Image = Properties.Resources.CountLines
};

// When we click, we'll count the lines.
itemCountLines.Click += (sender, args) => CountLines();

// Add the item to the context menu.
menu.Items.Add(itemCountLines);

// Return the menu.
return menu;
}

关于c# - 无法使用 C# 在 shell 扩展中添加图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16193249/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com