India Flag: +91.120.4106935 / 4202026
USA Flag : +1 (804) 591-0052
Logo

LW Employees

Highlight Text In Webbrowser Control On Mouse Double Click C#

Amit

Highlight Text In Webbrowser Control On Mouse Double Click C#

Posted in technical blogs

Highlight Text In Web browser Control C#. We are providing best web scraping and web crawling services by using C# language and scraping with manual coding

01    private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
02    {
03            if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)
04            {
05                   HtmlDocument _document = webBrowser1.Document;
06                   _document.MouseLeave += new HtmlElementEventHandler(document_MouseLeave);
07
08                   IHTMLDocument2 currentDoc = (IHTMLDocument2)webBrowser1.Document.DomDocument;
09                   HTMLDocumentEvents2_Event iEvent = (mshtml.HTMLDocumentEvents2_Event)currentDoc;
10                   iEvent.ondblclick += new HTMLDocumentEvents2_ondblclickEventHandler(iEvent_ondblclick);
11            }
12    }

01    private void document_MouseLeave(object sender, HtmlElementEventArgs e)
02    {
03             HtmlElement element = e.FromElement;
04             mshtml.HTMLElementEvents2_Event iEvent;
05             iEvent = element.DomElement as mshtml.HTMLElementEvents2_Event;
06             iEvent.ondblclick -=new HTMLElementEvents2_ondblclickEventHandler(iEvent_ondblclick);
07    }
08
09    bool iEvent_ondblclick(IHTMLEventObj pEvtObj)
10    {
11             if (pEvtObj.srcElement.innerText != null)
12             {
13                   //
14                   // Stop navigation on current click if it contains link.
15                   //
16                   if (pEvtObj.srcElement.outerHTML.Contains(“href”))
17                          webBrowser1.Stop();
18
19                   IHTMLDocument2 doc2 = wbMainPage.Document.DomDocument as IHTMLDocument2;
20                   StringBuilder html = new StringBuilder(doc2.body.outerHTML);
21                   String substitution = “” + pEvtObj.srcElement.innerText + “”;
22                   html.Replace(pEvtObj.srcElement.outerHTML, substitution);
23                   doc2.body.innerHTML = html.ToString();
24             }
25             return false;
26    }

give wings to your

business

smart it solutions for the most pressing problems

Leave a Reply

Your email address will not be published. Required fields are marked *

Shares