问题描述
好的,这里的初学者刚开始学习编程,尝试用 C# 做点什么.本质上,我有一个字符串..
Ok, beginner here just getting into learning programming, trying to make something in C#. Essentially, I have a string..
string resourcename = "example"
很方便,我还有一个名为 example.jpg 的资源.现在我正在尝试将我的背景图像设置为 example.jpg,使用字符串resourcename"而不是实际的文件名.通常我会这样做:
Conveniently enough, I also have a resource called example.jpg.. Now I'm trying to set my backgroundimage to example.jpg, using the string 'resourcename' instead of the actual filename..Normally I'd do this:
this.BackgroundImage = namespace.Properties.Resources.example;
所以现在我想做类似的事情
So now I'd like to do something like
this.BackgroundImage = namespace.Properties.Resources.resourcename;
显然,它无法识别,因为它是一个字符串,所以有什么方法可以将字符串合并到资源位置中吗?
Obviously, it doesn't recognize that because it's a string, so is there any way I can incorporate a string into the resource location?
谢谢!:D
推荐答案
结合前两个答案的想法,你可以尝试这样的事情:
Combining the ideas from the two previous answers, you might try something like this:
BackgroundImage = (Image)Properties.Resources.ResourceManager.GetObject(resourcename));
这篇关于我可以在 C# 中将字符串转换为资源位置吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!