这些方法都不适用于我,对于我的生活,我无法弄清楚为什么。一直在疯狂地搜索并在这个网站上徘徊,这是我在下面找到评论方法的地方。
无论我做什么,显示的内容都不会更新:'(
任何帮助将不胜感激..我束手无策。
private void Form1_Shown(object sender, EventArgs e)
{
string docText =
"<html><!DOCTYPE html>" + Environment.NewLine +
"<style type=\"text/css\"> #footer { position: absolute; bottom: 0; left: 0; height: 0px; } </style>" + Environment.NewLine +
"<script type=\"text/javascript\">" + Environment.NewLine +
"function appendHtml(o) {" + Environment.NewLine +
"var div = document.createElement(\"div\");" + Environment.NewLine +
"div.innerHTML = o;" + Environment.NewLine +
"document.body.appendChild(div);" + Environment.NewLine +
"}" + Environment.NewLine +
"</script>" + Environment.NewLine + "<body>" + Environment.NewLine + "</body></html>" +
//"<body></body>" +
//"<table align=\"center\" border=\"0px\" id=\"footer\" width=\"100%\"></table>" +
Environment.NewLine;
msgLog.DocumentText = docText;
Application.DoEvents();
HtmlTable table = new HtmlTable();
table.Width = "100%";
HtmlTableRow tr = new HtmlTableRow();
tr.Cells.Add(new HtmlTableCell("shit"));
tr.Cells[0].Width = "100%";
table.Rows.Add(tr);
InsertHtmlControl(table, msgLog);
}
public static void InsertHtmlControl(HtmlControl c, WebBrowser wb)
{
// create a HtmlTextWriter;
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htmlw = new HtmlTextWriter(sw);
// render the control as html
c.RenderControl(htmlw);
////invoke the script passing in the html
//object[] p = new object[1];
//p[0] = (object)sb.ToString();
//Trace.WriteLine("Invoking: " + sb.ToString());
//wb.Document.InvokeScript("appendHtml", p);
HtmlElement body = wb.Document.GetElementsByTagName("body")[0];
body.InnerHtml = sb.ToString();
wb.Update();
htmlw.Close();
htmlw.Dispose();
sw.Dispose();
}