[英]C#: How to get all Resources in Resources folder and their names
I have added many images in my Resources folder to use them in my project. 我在我的Resources文件夹中添加了许多图像,以便在我的项目中使用它们。 I want to call them dynamically in picture box by referring their names.
我想通过引用它们的名字在图片框中动态调用它们。 My problem is:
我的问题是:
Thank you. 谢谢。
you can get all the list of resources using Resources
class of your project. 您可以使用项目的
Resources
类获取所有资源列表。
var set = WindowsFormsApplication1.Properties.Resources.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true);
// How do I store images from Resources folder to a List or array?
var resourceList = set.Cast<System.Collections.DictionaryEntry>().Select(item => item.Value);
// How am I supposed to get names of all the images in a list or array?
var nameList = set.Cast<System.Collections.DictionaryEntry>().Select(item => item.Key);
// How do I get names of images with a particular prefix like img1, img2.... ?
var dicResources = set.Cast<System.Collections.DictionaryEntry>().ToDictionary(item => item.Key, item => item.Value);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.