获取资源文件

时间:2022-11-27 18:46:54

from:http://blog.csdn.net/bjddd192/article/details/4317909
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace WinFormDev

{

    public partial class FormResouce : Form

    {

        public FormResouce()

        {

            InitializeComponent();

        }

 

        private void FormResouce_Load(object sender, EventArgs e)

        {

            //获取资源文件:资源名称应为命名空间加相对路径,且资源为嵌入的资源

 

            //获取本程序集的资源文件

            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();

            System.IO.Stream stream = assembly.GetManifestResourceStream("WinFormDev.wait.gif");

            pictureBox1.Image = new System.Drawing.Bitmap(stream);

 

            //获取其它程序集的资源文件

            assembly = System.Reflection.Assembly.GetAssembly(typeof(Components.frmGradeEditor));

            stream = assembly.GetManifestResourceStream("Components.Resources.1.bmp");

            pictureBox2.Image = new System.Drawing.Bitmap(stream);

        }

    }

}