c#webbrowser没有更新/插入

时间:2013-09-10 19:28:43

标签: c# html

这些方法都不适合我和我的生活,我无法弄清楚为什么。谷歌搜索疯狂和徘徊这个网站,这是我在下面找到评论方法。

无论我做什么,显示的内容都不会更新:'(

任何帮助都会受到赞赏..我的斗智尽头。

        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();


    }

0 个答案:

没有答案