使用資源文件

1.讀取資源文件
ResourceManager resourceManager;
resourceManager = new ResourceManager(typeof(Form1).Namespace + ".res", Assembly.GetAssembly(typeof(Form1)));
ResourceSet resources = resourceManager.GetResourceSet(CultureInfo.CurrentCulture,true, true);
foreach(DictionaryEntry de in resources)
     {
...
     } 
2.寫資源文件
IResourceWriter writer = new ResourceWriter("myResources.resources");    
      // Adds resources to the resource writer.
      writer.AddResource("String 1", "First String");
      writer.AddResource("String 2", "Second String");
      writer.AddResource("String 3", "Third String");
      // Writes the resources to the file or stream, and closes it.
      writer.Close();
3.將圖片作爲資源文件
首先將圖片設置爲嵌入資源,如下圖。
Icon logo;
Stream strm = this.GetType().Assembly.GetManifestResourceStream(typeof(Form1).Namespace + .logo.ico");
if(strm != null)
     {
           logo = new Icon(strm, 112,103);
     }
     return logo;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章