窗口应用程序中的Web浏览器控件

时间:2013-02-20 08:52:32

标签: winforms

您好我正在使用此代码:

    private void Form1_Load(object sender, EventArgs e)
    {
        webBrowser1.Navigate("about:blank");

        HtmlDocument doc = webBrowser1.Document;
        doc.Write("<b><i>My Name</i> is Not </b> Khan.<b><i>My Name</i> is Not </b> Khan.<b><i>My Name</i> is Not </b> Khan.<b><i>My Name</i> is Not </b> Khan.");
    }
    private void button1_Click(object sender, EventArgs e)
    {
        webBrowser1.Navigate("about:blank");
        HtmlDocument doc = webBrowser1.Document;
        doc.Write("<b><i>My Name</i> is Not </b> Khan.<b>");
    }

但是当我点击按钮时,webBrowser1显示为空白。

1 个答案:

答案 0 :(得分:0)

尝试以下代码:

    private void Form1_Load(object sender, EventArgs e)
    {
        string strText = "<b><i>My Name</i> is Not </b> Khan.<b><i>My Name</i> is Not </b> Khan.<b><i>My Name</i> is Not </b> Khan.<b><i>My Name</i> is Not </b> Khan.";
        webBrowser1.Navigate("about:blank");
        HtmlDocument objHtmlDoc = this.webBrowser1.Document;
        objHtmlDoc.Write(String.Empty);
        webBrowser1.DocumentText = strText;
    }
    private void button1_Click(object sender, EventArgs e)
    {
        string strText="<b><i>My Name</i> is Not </b> Khan.<b>";
        webBrowser1.Navigate("about:blank");
        HtmlDocument objHtmlDoc = this.webBrowser1.Document;
        objHtmlDoc.Write(String.Empty);
        webBrowser1.DocumentText = strText;
    }
相关问题