mshtml突出显示网页中的所有文本

时间:2019-12-10 11:48:58

标签: c# highlight mshtml

它可以工作,但是当我滚动浏览器时,它会再次进行研究。

我将不胜感激,如果有办法阻止这种情况,我尝试将其放入一个bool变量中,就没有乐趣了

webBrowser1_DocumentCompleted

            //webBrowser1.Refresh();

Application.DoEvents();

if (webBrowser1.Document != null)
{
    mshtml.IHTMLDocument2 document = webBrowser1.Document.DomDocument as mshtml.IHTMLDocument2;
    if (document != null)
    {
        mshtml.IHTMLSelectionObject currentSelection = document.selection;

        mshtml.IHTMLTxtRange range = currentSelection.createRange() as mshtml.IHTMLTxtRange;

        while (range != null )
        {
            String search = "module";
            if (search == "")
            {
                MessageBox.Show("not selected");
            }
            else
            {
                    line1:

                    if ((range.findText(search)) && (range.htmlText != "span style='background-color: rgb(255, 255, 0);'>" + search + "</span>"))
                    {
                        range.select();
                        range.pasteHTML("<span style='background-color: rgb(255, 255, 0);'>" + search + "</span>");
                        //goto line1;

                    }

            }

        }
        //Do = false;

    }
    // Do = false;  //NO
}
//webBrowser1.Stop();
}

0 个答案:

没有答案
相关问题