(C++ WinForms VS 2022) 图标异常
当我尝试在属性窗口中更改表单的图标 (this) 时,此行代码在 .h 文件中生成:
this->Icon = (cli::safe_cast<System::Drawing::Icon^>(resources->GetObject(L"$this.Icon")));
但是当我尝试运行它时,它给了我一个 System.Resources.MissingManfiestResourceException 错误:
System.Resources.MissingManifestResourceException HResult=0x80131532 消息=找不到任何适合指定的资源 文化或中立文化。确保 “Thermodynamics_Generator.Form1.resources”已正确嵌入或 在编译时链接到程序集“thermodynamics_generator”,或者 所有所需的卫星组件都是可加载的并且完全 签署了。来源=mscorlib StackTrace:位于 System.Resources.ManifestBasedResourceGroveler.HandleResourceStreamMissing(字符串 文件名)位于 System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo 文化,Dictionary`2 localResourceSets,布尔值 tryParents,布尔值 createIfNotExists、StackCrawlMark&堆栈标记)在 System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestCulture,布尔值 createIfNotExists,布尔值 tryParents, StackCrawlMark&堆栈标记)在 System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo 文化、布尔值 createIfNotExists、布尔值 tryParents) at System.Resources.ResourceManager.GetObject(字符串名称,CultureInfo 文化,布尔值wrappUnmanagedMemStream)位于 System.Resources.ResourceManager.GetObject(字符串名称)位于 Thermodynamics_Generator.Form1.InitializeComponent() 中 C:\Users\my_name\source\repos\thermodynamics_generator\thermodynamics_generator\thermodynamics_generator.h:line 第1194章 C:\Users\my_name\source\repos\thermodynamics_generator\thermodynamics_generator\thermodynamics_generator.h:line 26 在 main() 中 C:\Users\my_name\source\repos\thermodynamics_generator\thermodynamics_generator\CppCLR_WinformsProject.cpp:line 11
我已经尝试了另一篇 帖子 中的类似操作来执行此操作:
this->Icon = gcnew System::Drawing::Icon(L"app.ico");
它可以工作,但是当在其他计算机上运行时,它根本不想运行(只想在我的计算机上运行)。
我还检查了 .resx 文件以查看 $this.Icon
是否存在,但仍然给了我一个例外。
如果我提到其他事情,请告诉我。
When I attempt to change the icon of the form in the properties window (this), this line of code gets generated in the .h file:
this->Icon = (cli::safe_cast<System::Drawing::Icon^>(resources->GetObject(L"$this.Icon")));
But when I try to run it, it gives me a System.Resources.MissingManfiestResourceException
error:
System.Resources.MissingManifestResourceException HResult=0x80131532
Message=Could not find any resources appropriate for the specified
culture or the neutral culture. Make sure
"Thermodynamics_Generator.Form1.resources" was correctly embedded or
linked into assembly "thermodynamics_generator" at compile time, or
that all the satellite assemblies required are loadable and fully
signed. Source=mscorlib StackTrace: at
System.Resources.ManifestBasedResourceGroveler.HandleResourceStreamMissing(String
fileName) at
System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo
culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean
createIfNotExists, StackCrawlMark& stackMark) at
System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo
requestedCulture, Boolean createIfNotExists, Boolean tryParents,
StackCrawlMark& stackMark) at
System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo
culture, Boolean createIfNotExists, Boolean tryParents) at
System.Resources.ResourceManager.GetObject(String name, CultureInfo
culture, Boolean wrapUnmanagedMemStream) at
System.Resources.ResourceManager.GetObject(String name) at
Thermodynamics_Generator.Form1.InitializeComponent() in
C:\Users\my_name\source\repos\thermodynamics_generator\thermodynamics_generator\thermodynamics_generator.h:line
1194 at Thermodynamics_Generator.Form1..ctor() in
C:\Users\my_name\source\repos\thermodynamics_generator\thermodynamics_generator\thermodynamics_generator.h:line
26 at main() in
C:\Users\my_name\source\repos\thermodynamics_generator\thermodynamics_generator\CppCLR_WinformsProject.cpp:line
11
And I have tried something like this from another post to do this instead:
this->Icon = gcnew System::Drawing::Icon(L"app.ico");
It works, but when ran on other computers, it just does not want to run at all (only wants to run on my computer).
I also checked the .resx file to see $this.Icon
is there but still gives me an exception.
If there is other things I mention, let me know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这行代码是自动生成的,其中$this.Icon包含文件路径,可以读取
GetObject()
的文档。和 文档指出我们可以得出结论,该程序没有找到您的资源文件。如果要在其他计算机上运行程序,必须保证图标路径与您的计算机一致。
编辑:
我建议您检查资源是否包含为项目,在解决方案资源管理器中选择所有文件,然后右键单击资源文件并选择包含在项目中。
This line of code is automatically generated, where $this.Icon contains the file path, you could read the documentation for the
GetObject()
. And the documentation states thatWe could conclude that the program did not find your resource file. If you want to run the program on other computers, you must ensure that the icon path is consistent with your computer.
Edit:
I suggest you to check if the resource is included as a project, select
All Files
inSolution Exploer
, then right click on the resource file and selectInclude In Project
.