gpt4 book ai didi

c# - 循环遍历一组图像资源 (.resx)

转载 作者:行者123 更新时间:2023-11-30 21:05:34 26 4
gpt4 key购买 nike

我在单独的 .resx 文件中有 3 组 9 个图像,我正在尝试弄清楚如何将一组循环到 9 个静态图片框中。

Loop through all the resources in a .resx file

我已经查看了上面链接中的一些解决方案,例如使用 ResXResourceReader,但是当我使用 GetEnumerator 方法时出现解析错误。

当我使用 ResourceSet resourceSet = MyResourceClass.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true); 行时, ResourceManager 没有定义 Form 类,或者当我创建自己的 ResourceManager 时的 GetResourceSet 方法。

实际上有一个名为 CreateFileBasedResourceManager 的方法,我已经涉足其中,但说实话,除了目录之外,我不太了解它需要的参数。

我还研究了一些涉及程序集和在运行时检索正在执行的图像程序集的解决方案,但我认为目前这有点超出我的理解范围。

谁能告诉我前两种方法做错了什么或者完全不同的方法?

最佳答案

查看 MSDN,您应该能够像这样迭代 RESX 文件中的值:

string resxFile = @".\CarResources.resx";


// Get resources from .resx file.
using (ResXResourceSet resxSet = new ResXResourceSet(resxFile))
{
// Retrieve the image.
Object image = resxSet.GetObject("NAMEOFFILE", true);
}

如果你想迭代 RESX 文件中的所有对象,你可以这样做:

using (ResXResourceReader resxReader = new ResXResourceReader(resxFile))
{
foreach (DictionaryEntry entry in resxReader) {
// entry.Key is the name of the file
// entry.Value is the actual object...add it to the list of images you were looking to keep track of
}
}

更多可以找到here .

关于c# - 循环遍历一组图像资源 (.resx),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11630398/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com