向WebBrowser写入HTML
向WebBrowser写入HTML:
这一句不可少 webBrowser1.Navigate("about:blank");
private void Form_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("about:blank");
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
return;
if (e.Url.AbsoluteUri.Equals("about:blank", StringComparison.OrdinalIgnoreCase))
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("<html>");
sb.AppendLine("<head><title></title></head>");
sb.AppendLine("<body>");
sb.AppendLine("<img alt=\"\" src=\"http://goo.gl/ynH9\"/>");
sb.AppendLine("</body>");
sb.AppendLine("</html>");
webBrowser1.Document.Write(sb.ToString());
}
}
{
webBrowser1.Navigate("about:blank");
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
return;
if (e.Url.AbsoluteUri.Equals("about:blank", StringComparison.OrdinalIgnoreCase))
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("<html>");
sb.AppendLine("<head><title></title></head>");
sb.AppendLine("<body>");
sb.AppendLine("<img alt=\"\" src=\"http://goo.gl/ynH9\"/>");
sb.AppendLine("</body>");
sb.AppendLine("</html>");
webBrowser1.Document.Write(sb.ToString());
}
}