Highlight a WebBrowser control

How you can scroll to the top of a web browser control. There is an iframe on the page I am loading, and the scrollbar starts from 20px down. This only happens in my application. I would like to automatically scroll up.

+3
source share
2 answers

A quick search gives: webBrowser1.Document.Window.ScrollTo(0, 200);

+2
source

If you want to scroll the contents of an iframe to the top, the following should help you.

You will need 2 things first:

  • Add link to C: \ Program Files \ Microsoft.NET \ Primary Interop Assemblies \ Microsoft.mshtml.dll
  • edit the tag <iframe>so that it has an identifier, for example:id="something"

Finally, the code:

HtmlElement ele = webBrowser1.Document.GetElementById("something");
mshtml.HTMLIFrameClass frame = ele.DomElement as mshtml.HTMLIFrameClass;
if (frame != null)
{
    mshtml.HTMLDocumentClass doc = frame.document as mshtml.HTMLDocumentClass;
    if (doc != null)
    {
        object i = 0;
        mshtml.HTMLWindow2Class win = doc.frames.item(ref i) as mshtml.HTMLWindow2Class;
        if(win != null)
            win.scrollTo(0, 0);
    }
}
0

Source: https://habr.com/ru/post/1795644/


All Articles