问题描述
我有一个WinForms项目,并添加多张图片的资源(项目属性 - >资源)。现在我有一个Form1.cs中,具有.resx文件一UserControl1.cs,并使用 Assembly.GetManifestResourceNames()
,它包含了3串即:
I have a WinForms project and added multiple images to the resources (project properties -> Resources). Now I have a Form1.cs, a UserControl1.cs with a .resx files, and using Assembly.GetManifestResourceNames()
, it contains 3 strings namely:
1 TestApplication1.Properties.Resources.resources,
2 TestApplication1.Form1.resources
3 TestApplication1.UserControl1.resources
1 TestApplication1.Properties.Resources.resources,2 TestApplication1.Form1.resources3 TestApplication1.UserControl1.resources
我需要什么,现在得到明显#1,其中包含我需要得到的图像文件。我需要做的是,我可以通过自己的索引访问这些图片列表。我可以访问这个没有问题单独的文件,但我有72张影像,所以我需要他们作为一个列表。所以我的问题是,我如何才能在#1这些图像作为一个列表
What I need to get now is obviously the files from #1 which contains the images I need to get. What I need to do is have a list that I can access these images through their indexes. I can access this files individually with no problem, but I have 72 images so I need them as a list. So my question is, how do I get these images in #1 as a list?
编辑:
难道就没有别的方式,以创建列表和我所有的72张图像的补充呢?或者是有一些办法,我可以从资源列表得到所有这些图像?另外,我不希望诉诸使用 System.IO
我将建立这个应用程序作为类库。
Is there no other way as to create a list and add all of my 72 images to it? Or is there some way that I can get all of these images from the resources as a list? Also, I don't want to resort to using System.IO
as I will build this application as a Class Library.
推荐答案
每个的.resx
文件编译成一个单一的复合型嵌入 *资源
位于在汇编资源的blob。我明白这是混乱的,因为它意味着术语资源过载指的的.resources
一滴都,也是每个blob的个别内容。
Each .resx
file is compiled into a single "composite" embedded *.resources
resource blob that is located in your assembly. I appreciate this is confusing as it means the term "resource" is overloaded to refer to both the .resources
blob, but also the individual contents of each blob.
使用的的ResourceManager
类从内部检索名为项的.resources
文件。
Use the ResourceManager
class to retrieve named items from within a .resources
file.
请注意,如果你使用Visual Studio中的的.resx
设计师,那么你就不需要使用的ResourceManager
直接,您只需使用生成的资源
类,像这样:
Note that if you're using the .resx
designer in Visual Studio then you don't need to use ResourceManager
directly, you simply use the generated Resources
class, like so:
using MyProject.Properties;
...
this.label1.Text = Resources.SomeLabelText;
(这里的 SomeLabelText
是按键的名称)
默认情况下,该设计器生成的资源
类将根据属性。code>子命名空间
By default, the designer-generated Resources
class will be under the Properties
child namespace.
要列举的资源,你需要使用的ResourceManager
,就像这样:
To enumerate resources you'll need to use ResourceManager
, like so:
ResourceSet rsrcSet = MyProject.Properties.Resources.ResourceManager.GetResourceSet( CultureInfo.CurrentCulture, false, true );
foreach( DictionaryEntry entry in rsrcSet ) {
String name = entry.Key;
Object resource = entry.Value;
}
这篇关于如何获得在资源列表中的所有图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!