【发布时间】:2014-08-27 07:09:32
【问题描述】:
我有一个图片框,我想根据用户在文本框中键入的内容在运行时将图像加载到其中。
我在我的项目中创建了一个名为 Formations.resx 的文件并将我的图像加载到其中。我尝试了以下两种方法,但都没有运气,我做错了什么?
pictureBoxFormation.Image = Properties.Resources.ResourceManager.GetObject("random_" + firstPoint) as Image;
这段代码执行得很好,但是我的图片框的.Image 属性没有被它更新,我猜这段代码没有专门在我的文件中查找,它在哪里查找?
ResourceManager rm = new ResourceManager("Formations", Assembly.GetExecutingAssembly());
pictureBoxFormation.Image = rm.GetObject("random_" + firstPoint) as Image;
这会抛出一个错误,如下:
An unhandled exception of type 'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll
Additional information: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Formations.resources" was correctly embedded or linked into assembly "WindowsFormsApplication1" at compile time, or that all the satellite assemblies required are loadable and fully signed.
【问题讨论】:
-
您的标题和帖子不匹配。请更改其中一个,使标题与您的问题相符。
-
哦对了,请贴出错误,我订购的水晶球还没到。
-
完成了。当我登录时,我有一个老问题在我解决之前问了一半,我删除了内容但没有删除标题。
-
第一个 sn-p 不起作用,因为您没有将图像添加到 Properties/Resources.resx 文件中。第二个不起作用,因为您的资源流名称错误。它以项目的默认命名空间名称为前缀。所以“WindowsFormsApplication1.Formations”应该是正确的名称。如果您正在考虑选择一个更好的项目名称,那么您现在就应该这样做。
-
将资源移动到属性/资源并且它工作。在问我的问题之前,我确实尝试将命名空间添加到第二种做事方式,但无济于事。我还将该项目重命名为更合适的名称。如果您添加您的 cmets 作为答案,我将很乐意接受,谢谢。
标签: c# winforms resources resourcemanager