zoukankan      html  css  js  c++  java
  • 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");

  • 相关阅读:
    cocos2d tiledmap
    cocos2d 例子编辑器
    cocos2d 粒子系统
    【leetcode】矩阵中的幸运数
    【leetcode】魔术索引
    【leetcode】多数元素
    【leetcode】整理字符串
    【leetcode】通过翻转子数组使两个数组相等
    【leetcode】珠玑妙算
    【leetcode】距离顺序排列矩阵单元格
  • 原文地址:https://www.cnblogs.com/zhangxiaoshuai/p/4866093.html
Copyright © 2011-2022 走看看