c# 嵌入资源文件
欢迎转载,转载请注明:转载自[ http://www.cnblogs.com/zjfree/ ]
开发环境:VS2005 C#
首先将要嵌入的资源拷贝到工程目录下。

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

获取嵌入资源代码如下:
| 1 2 3 4 5 6 7 8 9 10 | privatevoidForm1_Load(objectsender, EventArgs e){    Stream sm = Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsApplication3.嵌入文本.txt");    byte[] bs = newbyte[sm.Length];    sm.Read(bs, 0, (int)sm.Length);    sm.Close();    UTF8Encoding con = newUTF8Encoding();    stringstr = 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为工程名称
实例下载:https://files.cnblogs.com/zjfree/Embed.rar
使用系统嵌入资源功能
假设工程名称为:WindowsApplication3
打开菜单 [项目] - [属性] 选择[资源] [添加资源] [添加现有文件] 选择资源文件 设置资源名称

在程序中使用方法
| 1 2 | SoundPlayer play = newSoundPlayer(WindowsApplication3.Properties.Resources.Warning);play.Play(); | 
欢迎转载,转载请注明:转载自[ http://www.cnblogs.com/zjfree/ ]
 
                     
                    
                 
                    
                 
         
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号