如何将File.html从资源加载到WebBrowser组件中?
问题描述:
我希望问题清楚..
谢谢.
I hope the question is clear..
Thanks.
答
您并没有确切地说出您遇到的困难,所以这是整个过程:
1)确保File.html包含在构建中.
将生成操作"属性设置为嵌入式资源".
2)获取资源名称
You don''t say exactly what you''re having difficulty with, so here is the whole process:
1) Make sure File.html is included in the build.
Set the "Build Action" property to "Embedded Resource".
2) Get the name of the resource
string[] a = Assembly.GetEntryAssembly().GetManifestResourceNames();
foreach ( string s in a ) Debug.WriteLine( "\t" + s );
3)提取资源:
3) Extract the resource:
string html = null;
using ( var s = Assembly.GetExecutingAssembly()
.GetManifestResourceStream( "[name of resource.html]" ) )
using ( var r = new StreamReader( s ) )
html = r.ReadToEnd();
4)加载WebBrowser控件:
4) Load in WebBrowser control:
webBrowser1.DocumentText = html;
尼克
Nick