{"id":2598,"date":"2022-08-30T15:26:12","date_gmt":"2022-08-30T15:26:12","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/02\/04\/finding-the-text-and-highlighting-the-same-with-in-ihtmlelement-in-webbrowser-control-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:26:12","modified_gmt":"2022-08-30T15:26:12","slug":"finding-the-text-and-highlighting-the-same-with-in-ihtmlelement-in-webbrowser-control-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/finding-the-text-and-highlighting-the-same-with-in-ihtmlelement-in-webbrowser-control-collection-of-common-programming-errors\/","title":{"rendered":"Finding the text and highlighting the same with in IHtmlElement in webbrowser control-Collection of common programming errors"},"content":{"rendered":"<p>I have to implement the TTS functonality to read out the web page opened in webbrowser control, while the reading the the text also i have to highlighting the work the system is reading but i am unable to do same. I view post here but not get the actual output as i want. and also when i am trying thie below code i am getting the error &#8220;System.Runtime.InteropServices.COMException was unhandled Message=Exception from HRESULT: 0x800A025E&#8221; on the trg.select()<\/p>\n<pre><code>IHTMLDocument2 currentDoc = (IHTMLDocument2)webBrowser1.Document.DomDocument;\n\n                foreach (IHTMLElement elem in currentDoc.body.all)\n                {\n\n\n\n                            string[] splitSentences = elem.innerText.Split(\" \".ToCharArray());\n\n                            for (int i = 0; i &lt; splitSentences.Length; i++)\n                            {\n\n                                \/\/ highlight(splitSentences[i]);\n\n                                mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)(webBrowser1.Document.DomDocument);\n\n                                IHTMLBodyElement bodyElement = doc.body as IHTMLBodyElement;\n\n                                IHTMLTxtRange trg = bodyElement.createTextRange();\n\n\n                                if (trg.findText(splitSentences[i], 0, 0))\n                                {\n                                    trg.select();\n                                }\n\n                                \/\/if (trg != null)\n                                \/\/{\n                                \/\/    String SearchString = splitSentences[i];\/\/ \"Privacy\"; \/\/ This is the search string you're looking for.\n                                \/\/    int wordStartOffset = 0; \/\/ This is the starting position in the HTML where the word you're looking for starts at.\n                                \/\/    int wordEndOffset = SearchString.Length;\n                                \/\/    trg.move(\"character\", wordStartOffset);\n                                \/\/    trg.moveEnd(\"character\", wordEndOffset);\n\n                                \/\/    trg.select();\n                                \/\/}\n\n\n                                \/\/mshtml.IHTMLSelectionObject sel = (mshtml.IHTMLSelectionObject)doc.selection;\n\n                                \/\/mshtml.IHTMLTxtRange rng = (mshtml.IHTMLTxtRange)sel.createRange();\n                                \/\/\/\/ rng.collapse(false);\n                                \/\/if (rng.findText(splitSentences[i], 1000000, 0))\n                                \/\/{\n                                \/\/    rng.select();\n                                \/\/    sound_object.Speak(splitSentences[i], SpeechLib.SpeechVoiceSpeakFlags.SVSFlagsAsync);\n                                \/\/}\n                                \/\/sound_object.Speak(splitSentences[i], SpeechLib.SpeechVoiceSpeakFlags.SVSFlagsAsync);\n\n\n                    }\n                    Thread.Sleep(2000);\n                }\n<\/code><\/pre>\n<p>i know this code is not about to find the text with in an element, this will find the text with in whole page i want just figure out hows will it work but it is not working,<\/p>\n<p>Please suggest something usefull.<\/p>\n<p id=\"rop\"><small>Originally posted 2014-02-04 02:41:40. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have to implement the TTS functonality to read out the web page opened in webbrowser control, while the reading the the text also i have to highlighting the work the system is reading but i am unable to do same. I view post here but not get the actual output as i want. and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2598","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2598","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2598"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2598\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}