如何嵌入资源以便可以通过图标访问它?
我有一个使用 VS2005 的 C# 项目。基本上我有两个图标,一个用于应用程序,一个用于与应用程序关联的文件。
我已将这些文件与应用程序关联起来,并且我知道如何在注册表中设置它们的图标,但我只能将它们设置为应用程序图标,因为它似乎是唯一的外部资源。
我尝试过将图标放在资源文件 (.resx) 中,或者作为单独的文件 (.ico) 在编译时编译到 exe 中,但这两种方法都不起作用。
为了说明我的意思,我构建了该应用程序并使用 Resource Hacker 打开它,您会注意到那里只有两个图标之一,使用一个图标和一个图标组。
I have a C# project using VS2005. Basically I have two icons, one for the application, and one for files that are associated with the application.
I have associated these files with the application, and I know how to set their icons in the Registry, but I can only set them to the application icon because it seems to be the only external resource.
I've tried having the icons either in a resource file (.resx), or as a seperate file (.ico) which is compiled into the exe at compile time, but neither work.
To show what I mean, I've built the app and opened it with Resource Hacker, and you'll notice only one of the two icons is there, using one icon and one icon group.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为这是不可能的。您可能必须求助于 C++ 项目,您可以在其中以 shell 可以识别的方式嵌入图标。请注意,这并不意味着 dll 必须包含其他任何内容;)但我不认为 .NET 程序集可以包含 shell 兼容的资源。
I do not think it can be done. YOu may have to resort to a C++ project where you can embedd the icons in a way that can be recognized by the shell. Note that this does not mean the dll has to contain anything else ;) But I don't think .NET assemblies can contain shell compatible resources.
我相信您可以通过直接调用 C# 编译器来完成此操作。这个 MSDN 主题似乎包含有用的信息。
使用 csc.exe 处理资源
I believe you can do this by invoking the C# compiler directly. This MSDN topic seems to contain useful information.
Working with Resources Using csc.exe
最后我只是将 .ico 存储在嵌入 .exe 中的资源文件中,然后将其提取到其 AppData 文件夹以供 Explorer 使用。
In the end I just stored the .ico in a resource file embedded in the .exe and then extracted it to its AppData folder for Explorer to use.
我将 myicon.ico 作为嵌入式资源包含在设计器集中
this.Icon = new System.Drawing.Icon(GetType(), "myicon.ico");
I included myicon.ico as an Embedded Resource, then in the designer set
this.Icon = new System.Drawing.Icon(GetType(), "myicon.ico");