2

I've got a 3 sets of 9 images in seperate .resx files, and I'm trying to figure out how to loop a single set into 9 static picture boxes.

Loop through all the resources in a .resx file

I've looked through some of the solutions in the above link, like using ResXResourceReader, but it comes up with a parsing error when I use the GetEnumerator method.

When I use the ResourceSet resourceSet = MyResourceClass.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true); line, there's no definition for the ResourceManager within the Form class, or a GetResourceSet method when I create my own ResourceManager.

There is actually a method called CreateFileBasedResourceManager which I've dabbled in, but truth be told I don't understand the parameters it needs too well aside from the directory.

I've also looked at some of the solutions involving assemblies and retrieving the executing image assembly at runtime, but I think that's a little out of my depth at the moment.

Can anyone tell me what I'm doing wrong with the first two methods or maybe something entirely different?

4

2 に答える 2

2

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
     } 
  }

詳細はこちらをご覧ください

于 2012-07-24T13:09:12.750 に答える
2

これは古い質問であることは知っていましたが、今日は同じ問題が発生し、次のように BasePath プロパティを設定して解決しました。

oResReader = new ResXResourceReader(strInputFile);
oResReader.BasePath = Path.GetDirectoryName(strInputFile);

私はここでこの解決策を見つけました

于 2014-05-16T17:24:31.360 に答える