通过字符串winforms获取资源项 [英] Get a resource item by string winforms
问题描述
在 C# Winforms 应用程序中,如何通过字符串访问 Resources
?例如,我知道我可以执行 Properties.Resources.MyImage
但是,直到运行时我才知道我需要哪个图像.使用包含 "MyImage"
的字符串,我如何访问 Properties.Resources.MyImage
?理想情况下,我希望有一些简单的东西,例如 Properties.Resources["MyImage"]
,但经过一些搜索,一直无法找到快速解决方案.
In a C# Winforms app, how can I access Resources
via string? For example I know I can do Properties.Resources.MyImage
however, I won't know which image I need until runtime. With a string containing "MyImage"
, how can I access Properties.Resources.MyImage
? Ideally, I was hoping for something easy such as Properties.Resources["MyImage"]
, but with some searching around haven't been able to find a quick solution to this.
感谢任何帮助.
推荐答案
你可以像这样使用ResourceManager.GetObject()
:
string resourceName = "MyImageNameHere";
Bitmap bmp = (Bitmap)Properties.Resources.ResourceManager.GetObject(resourceName);
pictureBox1.Image = bmp;
这篇关于通过字符串winforms获取资源项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!