简体   繁体   English

对.exe和Form使用相同的图标

[英]Using the same icon for .exe and Form

In my WinForms app, if I set an icon for my app and an icon for my Form, the icon appears twice in my executable. 在我的WinForms应用程序中,如果我为应用程序设置了一个图标,为表单设置了一个图标,则该图标在我的可执行文件中出现两次。 Is it possible to avoid this? 有可能避免这种情况吗?

(This question has been asked before, here , but the answers didn't seem to solve the problem. vanmelle's answer appears to extract only one icon (eg, 16x16), Sunlight's answer extracts only the 32x32, and lc's answer doesn't solve the problem: there is still a duplicated icon in the executable.) (此问题以前在这里被问过,但是答案似乎并不能解决问题。vanmelle的答案似乎仅提取一个图标(例如16x16),Sunlight的答案仅提取32x32,而lc的答案无法解决问题:可执行文件中仍然有重复的图标。)

If it's not possible to accomplish this task, why is this? 如果无法完成此任务,为什么会这样? What is it about using the same icon for an executable and a Form that's so hard in WinForms? 在可执行文件和WinForms中很难使用的窗体中使用相同的图标有什么用?

This is an inevitable consequence of running managed code on a completely unmanaged operating system. 这是在完全不受管的操作系统上运行受管代码的必然结果。 Windows Explorer only knows how to read unmanaged resources. Windows资源管理器只知道如何读取非托管资源。 You can see what they look like, use File + Open + File in Visual Studio and select your .exe. 您可以看到它们的外观,在Visual Studio中使用File + Open + File,然后选择.exe。 You'll typically see three resource groups listed there: 通常,您会在此处看到三个资源组:

  • RT_MANIFEST, contains the manifest that tells Windows that your program is Vista aware RT_MANIFEST,包含告诉Windows您的程序支持Vista的清单。
  • Version, contains the file version resource with values derived from your AssemblyInfo.cs file. 版本,包含文件版本资源,其值源自您的AssemblyInfo.cs文件。 You see its content when you use Properties + Details tab in Explorer. 在资源管理器中使用“属性+详细信息”选项卡时,可以看到其内容。 Note how the super important [AssemblyVersion] isn't visible in Vista and up 注意超级重要的[AssemblyVersion]在Vista和更高版本中不可见
  • Icon, contains the icon you added. 图标,包含您添加的图标。

This unmanaged resource data is separate from the managed resources you added. 此非托管资源数据您添加的托管资源是分开的。 Managed resources are compiled into the assembly manifest. 托管资源被编译到程序集清单中。 Unmanaged resources are stored in the .rsrc section of the image file. 非托管资源存储在映像文件的.rsrc部分中。 You can override the auto-generated version with the /win32res command line option. 您可以使用/ win32res命令行选项覆盖自动生成的版本。 Which requires a .res file, a binary file that is generated from a .rc resource script by the rc.exe resource compiler. 这需要一个.res文件,这是一个由rc.exe资源编译器从.rc资源脚本生成的二进制文件。 An age old Windows SDK tool. 古老的Windows SDK工具。

This may change some day, the super-secret Midori project is a rumored to focus on a managed operating system. 这可能有一天会改变,有传言称超级秘密Midori项目将重点放在托管操作系统上。 For now, we'll have to make do with the glue. 现在,我们必须使用胶水。

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

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