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");

 

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值