3
我使用此代碼在HTML中查找CDE
。我如何才能找到在標籤頁我的請求數據與不同的ID,例如,如果頁面的id 我的結果是CDE當頁ID爲我的結果是IJK,如何設置ID-在我的搜索價值?如何在WebBrowser控件中找到特定單詞C#
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.DocumentText = @"<html><head><title></title></head><body>"
+ "<page id=\"1\">"
+ @"ABCDEF</page>"
+ "<page id=\"2\">"
+ @"GHIJKLMN</page></body></html>";
webBrowser1.DocumentCompleted += HtmlEditorDocumentCompleted;
}
void HtmlEditorDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
var document = (IHTMLDocument2)((WebBrowser)sender).Document.DomDocument;
if (document != null)
{
IHTMLBodyElement bodyElement = document.body as IHTMLBodyElement;
if (bodyElement != null)
{
IHTMLTxtRange trg = bodyElement.createTextRange();
if (trg != null)
{
trg.move("character", 2);
trg.moveEnd("character", 3);
trg.select();
trg.pasteHTML("<font color=#FF0000><strike>" + trg.text + "</strike></font>");
}
}
}
}