• C#生成并引用资源文件


    C#生成并引用资源文件可以使用任何信息,图片,字符,尤其是图片信息,比DLL要广泛得多。



    下面创建一个资源文件

    using System;
    using System.Resources;
    using System.Drawing;

    namespace ConsoleApplication1
    {
    /// <summary>
    /// Class1 的摘要说明。
    /// </summary>
    class Class1
    {
    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main(string[] args)
    {
    ResourceWriter rw = new ResourceWriter(@"D:ConsoleApplication1objDebugwwww.resources");
    using (Image image = Image.FromFile(@"D:ConsoleApplication1objDebuglogo.gif"))
    {/*
      * 在 using 语句中创建一个实例,确保退出 using 语句时在对象上调用 Dispose。
      * 当到达 using 语句的末尾,
      * 或者如果在语句结束之前引发异常并且控制离开语句块,都可以退出 using 语句。
      * 
      */

    rw.AddResource("WroxLogo", image);
    rw.AddResource("Title", "Professional C#");
    rw.AddResource("Chapter", "Assemblies");
    rw.AddResource("Author", "Christian Nagel");
    rw.AddResource("Publisher", "Wrox Press");
    rw.Close();
    }
    }
    }
    }



    例外一个工程中下面代码装载上面创建的资源

    Assembly assembly = Assembly.GetExecutingAssembly();

    rm = new System.Resources.ResourceManager("WindowsApplication1.wwww",assembly);

    logo.Image = (Image)rm.GetObject("WroxLogo");
    textBoxTitle.Text = rm.GetString("Title");
    textBoxChapter.Text = rm.GetString("Chapter");
    textBoxAuthor.Text = rm.GetString("Author");
    textBoxPublisher.Text = rm.GetString("Publisher");

  • 相关阅读:
    逻辑卷的创建
    文件及目录的权限详解
    python之数据驱动Excel+ddt操作(方法二)
    python之数据驱动Excel操作(方法一)
    python + Excel数据读取(更新)
    selenium3 + python
    python+selenium+unittest发送Mail163邮件(PO)
    python自动发邮件库yagmail
    python之数据驱动yaml操作
    python之数据驱动ddt操作(方法四)
  • 原文地址:https://www.cnblogs.com/zhangxiaoshuai/p/4866093.html
Copyright © 2020-2023  润新知