前两天由于程序的需要,有些资源需要使用,想放在资源文件中,在网上查了一些资料,发些资源文件的使用有几种方式,比如像利用资源文件实现多语言版本程序的情况,但这种资源文件的使用一般是嵌入到程序中,只能读,还没有查到可写的资料。

另外一种方式就是做成外部的资源文件,这样就可读可写了,在这里贴一些代码

引用 using System.Resources;

 

写资源文件代码如下:

 

 

C# 读写外部的资源文件            ResourceWriter rw = new ResourceWriter("Greeting1.dll");
C# 读写外部的资源文件            Bitmap b 
= new Bitmap("hhw.gif");
C# 读写外部的资源文件
 
C# 读写外部的资源文件
C# 读写外部的资源文件            
//add some strings to the file
C# 读写外部的资源文件            
//rw.AddResource("Greeting", "Welcome to Microsoft .Net Framework!Test");
C# 读写外部的资源文件            
//rw.AddResource("PasswordException", "Sorry, that is not the correct password.");
C# 读写外部的资源文件            
//rw.AddResource("Purchase", "Please select an item to purchase from the store:");
C# 读写外部的资源文件            
//rw.AddResource("Goodbye", "Thank you for visiting Microsoft .Net Framework!");
C# 读写外部的资源文件
            rw.AddResource("flag",b );
C# 读写外部的资源文件
C# 读写外部的资源文件 
C# 读写外部的资源文件            
C# 读写外部的资源文件            rw.Generate();
C# 读写外部的资源文件            rw.Close();  

 

以上注释的代码都可以打开使用

 

读资源文件的代码

 

C# 读写外部的资源文件            ResourceReader rr = new ResourceReader("Greeting1.dll");
C# 读写外部的资源文件           String s 
= "";
C# 读写外部的资源文件           
//iterate through the reader, printing out the name-value pairs
C# 读写外部的资源文件
           foreach (DictionaryEntry d in rr) 
           rr.Close();

 

 

相关文章:

  • 2021-07-31
  • 2021-09-25
  • 2022-12-23
  • 2022-01-20
  • 2021-10-07
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-06
  • 2022-12-23
  • 2022-12-23
  • 2022-01-22
  • 2022-12-23
相关资源
相似解决方案