我有一个图片框,我想在运行时加载图片,具体取决于用户在文本框中输入的内容。
我在项目中创建了一个名为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.
答案 0 :(得分:1)
根据Hans Passant的建议,将资源移至属性/资源,在原始帖子的评论中有所描述。