百度搜索了一大堆,发现大部分说得都不够详细,于是只好自己记录下了。
- 添加文件
菜单:【项目】>【添加现有项】,在弹出的对话框内选择相应文件(比如:Loading.swf)。 - 设置文件属性
在【解决方案资源管理器】内,找到刚添加的文件Loading.swf,右击选择【属性】
将其【生成操作】一栏参数设为【嵌入的资源】 - 添加代码
Public Sub 释放文件(ByVal 文件名 As String, ByVal 路径 As String) Try Dim 文件流 As IO.Stream = Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream(My.Application.Info.AssemblyName + "." + 文件名) '获取资源文件的流 Dim 文件内容(文件流.Length - 1) As Byte '定义数组 Dim 新文件 As New IO.FileStream(路径 + "\" + 文件名, IO.FileMode.OpenOrCreate) '创建文件 文件流.Read(文件内容, 0, 文件内容.Length) 新文件.Write(文件内容, 0, 文件内容.Length) 文件流.Close() 新文件.Close() Catch ex As System.IO.D irectoryNotFoundException MessageBox.Show("未找到以下路径:" + 路径, "错误", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) Catch ex As System.NullReferenceException MessageBox.Show("未发现资源文件:" + 文件名, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error) Catch ex As exception Msgbox(ex.message) End Try End Sub
- 在需要的地方调用上述函数即可。如释放文件(“Loading.swf”, 存储位置),注:区分大小写,且不管该文件是否放在某一特定文件夹内都应只写文件名(C#需包含具体文件夹名)。
案例下载:链接: http://pan.baidu.com/s/1sjoFgiL 密码: 3dn6
另请参阅:http://www.cnblogs.com/chiname/articles/133034.html