如何嵌入资源以便可以通过图标访问它?

发布于 2024-08-31 03:29:48 字数 566 浏览 2 评论 0原文

我有一个使用 VS2005 的 C# 项目。基本上我有两个图标,一个用于应用程序,一个用于与应用程序关联的文件。

我已将这些文件与应用程序关联起来,并且我知道如何在注册表中设置它们的图标,但我只能将它们设置为应用程序图标,因为它似乎是唯一的外部资源。

我尝试过将图标放在资源文件 (.resx) 中,或者作为单独的文件 (.ico) 在编译时编译到 exe 中,但这两种方法都不起作用。

为了说明我的意思,我构建了该应用程序并使用 Resource Hacker 打开它,您会注意到那里只有两个图标之一,使用一个图标和一个图标组。

http://img442.imageshack.us/img442/3189/resourcesx.jpg http://img442.imageshack.us/img442/3189/resourcesx.jpg http:/ /img442.imageshack.us/img442/3189/resourcesx.jpg

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.

http://img442.imageshack.us/img442/3189/resourcesx.jpg http://img442.imageshack.us/img442/3189/resourcesx.jpg

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

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

发布评论

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

评论(4

李不 2024-09-07 03:29:48

我认为这是不可能的。您可能必须求助于 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.

孤独患者 2024-09-07 03:29:48

我相信您可以通过直接调用 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

从此见与不见 2024-09-07 03:29:48

最后我只是将 .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.

小伙你站住 2024-09-07 03:29:48

我将 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");

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