C# 在一组图像资源(.resx)中循环

C# 在一组图像资源(.resx)中循环,c#,resources,resx,C#,Resources,Resx,我在单独的.resx文件中有3组9幅图像,我正试图找出如何将一组图像循环到9个静态图片框中 我已经浏览了上面链接中的一些解决方案,比如使用ResXResourceReader,但是当我使用GetEnumerator方法时,它出现了一个解析错误 当我使用ResourceSet-ResourceSet=MyResourceClass.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture,true,true)时行,在表单类中没有Res

我在单独的.resx文件中有3组9幅图像,我正试图找出如何将一组图像循环到9个静态图片框中

我已经浏览了上面链接中的一些解决方案,比如使用
ResXResourceReader
,但是当我使用
GetEnumerator
方法时,它出现了一个解析错误

当我使用
ResourceSet-ResourceSet=MyResourceClass.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture,true,true)时行,在
表单
类中没有
ResourceManager
的定义,或者在创建自己的
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
     } 
  }
oResReader = new ResXResourceReader(strInputFile);
oResReader.BasePath = Path.GetDirectoryName(strInputFile);

可以找到更多信息。

查看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
     } 
  }
oResReader = new ResXResourceReader(strInputFile);
oResReader.BasePath = Path.GetDirectoryName(strInputFile);

可以找到更多信息。

我知道这是一个老问题,但今天我遇到了同样的问题,并解决了设置BasePath属性的问题,如下所示:

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
     } 
  }
oResReader = new ResXResourceReader(strInputFile);
oResReader.BasePath = Path.GetDirectoryName(strInputFile);

我找到了这个解决方案

我知道这是一个老问题,但今天我遇到了同样的问题,并解决了设置BasePath属性的问题,如下所示:

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
     } 
  }
oResReader = new ResXResourceReader(strInputFile);
oResReader.BasePath = Path.GetDirectoryName(strInputFile);

我找到了这个解决方案

当它查看我所查看的resx文件中的第一个图像时,我不断出现一个解析错误。string resxFile=@”//file path以me1images.resx结尾;正在使用(ResXResourceReader resxReader=new ResXResourceReader(resxFile)){foreach(resxReader中的DictionaryEntry条目){string resourceKey=entry.Key.ToString();object resource=entry.Value;MessageBox.Show(“message”);}这一切都在一个try-catch中:ArgumentException是未处理的ResX文件找不到路径“//FilePath\bin\resources\1336578195503.jpg”的一部分。第123行,位置5。无法分析。@Jamz并且该文件存在于\bin\resources文件夹中?当它查看我让它查看的resx文件中的第一个图像时,我一直遇到一个分析错误。string resxFile=@”//file path以me1images.resx结尾;正在使用(ResXResourceReader resxReader=new ResXResourceReader(resxFile)){foreach(resxReader中的DictionaryEntry条目){string resourceKey=entry.Key.ToString();object resource=entry.Value;MessageBox.Show(“message”);}这一切都在一个try-catch中:ArgumentException是未处理的ResX文件找不到路径“//FilePath\bin\resources\1336578195503.jpg”的一部分。第123行,位置5。无法分析。@Jamz并且该文件存在于\bin\resources文件夹中?