C# 操作资源文件

(1)首先引用这两个命名空间

(2)两种方式调用资源文件中的内容

        private void button2_Click(object sender, EventArgs e)
        {
            //通过ResourceManager类获取
            ResourceManager rm = new ResourceManager("WindowsFormsApplication1.Properties.Resources", Assembly.GetExecutingAssembly());
            pictureBox1.Image = (Image)rm.GetObject("Image1");
            MessageBox.Show((String)rm.GetObject("String1"));

            //直接使用
            pictureBox1.Image = WindowsFormsApplication1.Properties.Resources.Image1; 
            MessageBox.Show(WindowsFormsApplication1.Properties.Resources.String1);
        }

其中的 “WindowsFormsApplication1.Properties.Resources” 就是资源在本项目的命名空间路径,如图:

原文地址:https://www.cnblogs.com/webcyz/p/6540231.html