webbrowser控件怎样调用嵌入资源中的网页?
// webBrowser1
//
this.webBrowser1.CausesValidation = false;
this.webBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
this.webBrowser1.Location = new System.Drawing.Point(3, 3);
this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
this.webBrowser1.Name = "webBrowser1";
this.webBrowser1.Size = new System.Drawing.Size(681, 190);
this.webBrowser1.TabIndex = 0;
this.webBrowser1.Url = new System.Uri("d:\\a\\a.html", System.UriKind.Absolute);
一个简单的 webbrowser 控件,url指向本地d盘的一个网页文件,我想把这个路径换成嵌入资源中的网页,代码应该怎么写呢?
------解决方案--------------------使用DocumentText 属性
webBrowser1.DocumentText = WindowsFormsApplication1.Properties.Resources.htm;
或者使用stream:
using (Stream stream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream("1.htm"))
{
using (StreamReader reader = new StreamReader(stream))
{
webBrowser1.DocumentText = reader.ReadToEnd();
}
}
来自
http://stackoverflow.com/questions/10598087/webbrowser-in-windows-forms-how-to-load-html-page-from-resources