通过字符串winforms获取资源项

Mr *_*me8 2 c# resources winforms

在 C# Winforms 应用程序中,如何Resources通过字符串访问?例如,我知道我可以做到,Properties.Resources.MyImage但是直到运行时我才知道我需要哪个图像。使用包含 的字符串"MyImage",我如何访问Properties.Resources.MyImage?理想情况下,我希望有一些简单的东西,例如Properties.Resources["MyImage"],但经过一些搜索,无法找到快速解决方案。

任何帮助表示赞赏。

Idl*_*ind 5

你可以这样使用ResourceManager.GetObject()

string resourceName = "MyImageNameHere";
Bitmap bmp = (Bitmap)Properties.Resources.ResourceManager.GetObject(resourceName);
pictureBox1.Image = bmp;
Run Code Online (Sandbox Code Playgroud)