zoukankan      html  css  js  c++  java
  • [转载]c# 嵌入资源文件

    转载自:http://www.cnblogs.com/zjfree/archive/2011/01/13/1934231.html

    开发环境:VS2005 C#

    首先将要嵌入的资源拷贝到工程目录下。

    设置文件生成操作为:嵌入的资源

    获取嵌入资源代码如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    private void Form1_Load(object sender, EventArgs e)
    {
        Stream sm = Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsApplication3.嵌入文本.txt");
        byte[] bs = new byte[sm.Length];
        sm.Read(bs, 0, (int)sm.Length);
        sm.Close();
        UTF8Encoding con = new UTF8Encoding();
        string str = con.GetString(bs);
        MessageBox.Show(str);
    }

    注意:WindowsApplication3.嵌入文本.txt WindowsApplication3为工程名称

    实例下载:https://files.cnblogs.com/zjfree/Embed.rar

    使用系统嵌入资源功能

    假设工程名称为:WindowsApplication3

    打开菜单 [项目] - [属性] 选择[资源] [添加资源] [添加现有文件] 选择资源文件 设置资源名称


    在程序中使用方法

    1
    2
    SoundPlayer play = new SoundPlayer(WindowsApplication3.Properties.Resources.Warning);
    play.Play();
  • 相关阅读:
    python常用库
    python多线程
    python内存泄漏
    用python实现js语言里的特性
    nginx + uwsgi
    mysql语句
    urllib模块
    提取数据xpath,re,css
    selenium模块
    脱壳
  • 原文地址:https://www.cnblogs.com/linyefeilyft/p/2957100.html
Copyright © 2011-2022 走看看