C#c#窗口中的資源讀取 Form.resx

 

1、Form1.resx資源的訪問  

 

using System.Resources;

[/// <summary>   
  1. /// 從資源中加載圖片   
  2. /// </summary>   
  3. /// <param name="sender"></param>   
  4. /// <param name="e"></param>   
  5. private void button1_Click(object sender, EventArgs e)  
  6. {  
  7.     //資源管理"typeof(Form1)"指定爲Form1.resx,可以改成其他的  
  8.     ResourceManager rm = new ResourceManager(typeof(Form1));  
  9.     //類型轉換   
  10.     //"Image1"是資源名稱   
  11.     Bitmap bitMap = (Bitmap)rm.GetObject("Image1");  
  12.     //顯示   
  13.     this.pictureBox1.Image = bitMap;  
  14. }  
  15. /// <summary>   
  16. /// 從資源中顯示字符串   
  17. /// </summary>   
  18. /// <param name="sender"></param>  
  19. /// <param name="e"></param>   
  20. private void button2_Click(object sender, EventArgs e)  
  21. {  
  22.     ResourceManager rm = new ResourceManager(typeof(Form1));  
  23.     //顯示字符串   
  24.     //"String1"是資源名稱   
  25.     this.textBox1.Text = rm.GetString("String1");  

 

其他資源文件訪問參考

http://www.soaspx.com/dotnet/csharp/csharp_20111213_8397.html

 

2、Resources.resx資源的訪問

            ResourceManager rm2 = Properties.Resources.ResourceManager;
             Bitmap bitMap = (Bitmap)rm2.GetObject("_10");
             this.BackgroundImage = bitMap;
             this.BackgroundImageLayout = ImageLayout.Stretch;

             this.Text = rm2.GetString("String1");

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章