Discussion:
Scrolling the WebBrowser control
(too old to reply)
Futronics Developer
2008-04-07 10:46:00 UTC
Permalink
I'm trying to do my own scrolling with the WebBrowser control.

I can use the WebBrowser.Document.Window.ScrollTo method to scroll to a
specific position but how do I get my current position?

I can keep my own scroll position, I know when the document loads that I'm
at scroll position 0,0. Then each time I scroll (by 200 for example) I just
keep a record of my new scroll position.

This works until I get to the end of the document. The ScrollTo doesn't
return any feedback when it gets to the end of the document, so I don't know
when stop scrolling and when to stop adding 200 to my internal scroll
position.

Is there a way to read the current scroll position?
Tor Vidvei
2010-12-05 08:27:30 UTC
Permalink
You can read the current scroll position from the documents body element. You get the body element by means of GetElementsByTagName. Something like this:

Rectangle scrollRect;
// X,Y: Scrollposition
// Width,Height: Size of the displayed document

if (webBrowser1.Document != null)
{
HtmlElement body = webBrowser1.Document.GetElementsByTagName("body")[0];
if (body != null)
{
scrollRect = body.ScrollRectangle;
}
}
Post by Futronics Developer
I'm trying to do my own scrolling with the WebBrowser control.
I can use the WebBrowser.Document.Window.ScrollTo method to scroll to a
specific position but how do I get my current position?
I can keep my own scroll position, I know when the document loads that I'm
at scroll position 0,0. Then each time I scroll (by 200 for example) I just
keep a record of my new scroll position.
This works until I get to the end of the document. The ScrollTo doesn't
return any feedback when it gets to the end of the document, so I don't know
when stop scrolling and when to stop adding 200 to my internal scroll
position.
Is there a way to read the current scroll position?
Submitted via EggHeadCafe
Microsoft ASP.NET For Beginners
http://www.eggheadcafe.com/training-topic-area/ASP-NET/7/ASP.aspx
Loading...