0

我有一个图片框,我想根据用户在文本框中键入的内容在运行时将图像加载到其中。

我在我的项目中创建了一个名为 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.

4

1 回答 1

1

最终按照 Hans Passant 的建议将资源移动到 Properties/Resources,在原始帖子的评论中进行了描述。

于 2014-10-23T15:46:46.693 回答