The following C# code will programmatically scroll the browser window. The steps are easy.
First, add your web browser control to the form.
Second, add an event handler for the document completed event:
private void Form1_Load(object sender, EventArgs e) { this.webBrowser1.Url = new Uri("http://news.google.com"); HtmlDocument doc = this.webBrowser1.Document; this.webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler( webBrowser1_DocumentCompleted); }
Third, fill in the event handler:
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { HtmlDocument doc = this.webBrowser1.Document; doc.Body.ScrollTop = 300; return; }
You can then programmatically set the body's scrolltop property to adjust the position of the body element within the scrollable area. For example, this is the page without the event handler code added:
And now with the scrolling code added:
Remember Me
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.