基于一个ID,我想自动将一个图像加载到我的GUI中。为此,我希望能够从Visual Studio 2008中的Resources.resx文件中获取所有图像(使用C#)。我知道如果我知道自己是什么人,我一次就能拿到一个:
Image myPicture = Properties.Resources.[name of file];
但是我正在寻找的是这些路线...
foreach(Bitmap myPicture in Properties.Resources) {Do something...}
最佳答案
只需使用Linq(tm)
ResourceManager rm = Properties.Resources.ResourceManager;
ResourceSet rs = rm.GetResourceSet(new CultureInfo("en-US"), true, true);
if (rs != null)
{
var images =
from entry in rs.Cast<DictionaryEntry>()
where entry.Value is Image
select entry.Value;
foreach (Image img in images)
{
// do your stuff
}
}
关于c# - 获取所有(Properties.Resources)要存储在字典中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/849299/