秋枫落叶

秋天到了,枫叶落地,化为尘土

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: :: 管理 ::

转载自: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();
posted on 2013-03-13 10:18  林叶飞  阅读(206)  评论(0编辑  收藏  举报