ResXResourceWriter 与ResourceWriter 需要引入System.Resources
ResXResourceWriter 还必须引入System.Windows.Forms程序集
1.ResourceWriter生成二进制资源文件,生成的文件的后缀名: .resources, 而ResxResourceWriter编写生成基于XML的資源文件,生成的后缀名: .resx
ResXResourceWriter rrw = new ResXResourceWriter("demo.resx");
Image image = Image.FromFile(@"F:PersonalIconsWebIconwebicon 01.gif");
rrw.AddResource("ApplicationTitle", "myworld");
rrw.AddResource("testimage", image);
rrw.Generate();
rrw.Close();
注意创建ResXResourceWriter实例化时文件名 demo.resx,生成在Bin目录
ResourceWriter rw = new ResourceWriter("demo.resources");
Image image = Image.FromFile(@"F:PersonalIconsWebIconwebicon 01.gif");
rw.AddResource("ApplicationTitle", "myworld");
rw.AddResource("testimage", image);
rw.Generate();
rw.Close();注意创建ResourceWriter实例化时文件名demo.resources,生成在Bin目录
2.读取两种文件的方式有一定区别
ResourceManager rm = new ResourceManager("WindowsApplication1.demo", this.GetType().Assembly);
string test = rm.GetString("ApplicationTitle").ToString();
Image image = (Image)rm.GetObject("testimage");
this.pictureBox1.Image = image;
实例化ResourceMananger时构造函数的参数要以"命名空间名.resx文件名的"方式来命名,如:类的命名空间为testNamespace
而resx的文件名为:demo.resx的话,那该参数为:testNamespace.demo
ResourceManager rm = new ResourceManager("demo", this.GetType().Assembly);
string test = rm.GetString("ApplicationTitle").ToString();
Image image = (Image)rm.GetObject("testimage");
this.pictureBox1.Image = image;
实例化ResourceMananger时构造函数的参数要以"文件名"方式來命名,如:资源文件demo.resources文件,那该参数为:
demo
這是我个人的理解,理解不深难免有错误,请各位指正。(摘录)