1、Form1.resx资源的访问
using System.Resources;
- /// 从资源中加载图片
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button1_Click(object sender, EventArgs e)
- {
- //资源管理"typeof(Form1)"指定为Form1.resx,可以改成其他的
- ResourceManager rm = new ResourceManager(typeof(Form1));
- //类型转换
- //"Image1"是资源名称
- Bitmap bitMap = (Bitmap)rm.GetObject("Image1");
- //显示
- this.pictureBox1.Image = bitMap;
- }
- /// <summary>
- /// 从资源中显示字符串
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button2_Click(object sender, EventArgs e)
- {
- ResourceManager rm = new ResourceManager(typeof(Form1));
- //显示字符串
- //"String1"是资源名称
- 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");