I have a WinForms app for .NET Framework that allows the user to work with HTML pages. HTML pages are rendered in the intrinsic .NET WebBrowser control. The app allows the user to find text in the viewed HTML page. As a part of this functionality, the WebBrowser control should scroll the HTML page so that the found text becomes visible in the viewport. The core part of this algorithm is built with the MSHTML library and looks like this:
IHTMLDocument2 htmlDocument = WebBrowser.Document.DomDocument as IHTMLDocument2;
IHTMLSelectionObject selection = htmlDocument.selection;
IHTMLTxtRange rangeScroll = selection.createRange() as IHTMLTxtRange;
if (rangeScroll != null)
{
if (rangeScroll.findText(SearchPhrases[0]))
{
rangeScroll.scrollIntoView(true);
}
}
Some HTML pages contain hidden text (for example, inside tags with the "display: none" CSS style). The user may enter a word to search that can be present on a page 2 times - the first occurrence can be in the hidden area, the other one can be in the visible part. The problem is that I need to find and scroll into the viewport the visible word, but I do not know how to determine if the text in the IHTMLTxtRange rangeScroll object is visible. Can we retrieve this information from IHTMLTxtRange anyhow?