打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
c# 嵌入资源文件

欢迎转载,转载请注明:转载自[ http://www.cnblogs.com/zjfree/ ]

开发环境: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);
}
汉字乱码Stream sm = Assembly.GetExecutingAssembly().GetManifestResourceStream("嵌入资源.会泽代码.txt");            byte[] bs = new byte[sm.Length];            sm.Read(bs, 0, (int)sm.Length);            sm.Close();            string str = Encoding.GetEncoding("GB2312").GetString(bs);        ;            MessageBox.Show(str);

 字符串: MessageBox.Show(嵌入资源.Properties.Resources.mystr);

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

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

 

使用系统嵌入资源功能

假设工程名称为:WindowsApplication3

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


在程序中使用方法

1
2
SoundPlayer play = new SoundPlayer(WindowsApplication3.Properties.Resources.Warning);
play.Play();
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
WebService开发笔记 2 -- VS 2005 访问WebServcie更简单
MFC窗口位置和大小的获取
CString类型字符串,转换到 BYTE类型
Byte Array to String
C# stiring 专题
BSTR 字符串
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服