简体   繁体   English

C#:如何获取Resources文件夹中的所有资源及其名称

[英]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: 我的问题是:

  1. How do I store images from Resources folder to a List or array? 如何将Resources文件夹中的图像存储到List或数组中?
  2. How am I supposed to get names of all the images in a list or array? 我怎么能得到列表或数组中所有图像的名称?
  3. How do I get names of images with a particular prefix like img1, img2.... ? 如何获取具有特定前缀的图像名称,如img1,img2 ....?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM