Discussion:
How do I scroll the WebBrowser control
(too old to reply)
Futronics Developer
2008-05-13 12:00:01 UTC
Permalink
I'm trying to do my own scrolling with the WebBrowser control (2 large
buttons next to the control).

I can use the WebBrowser.Document.Window.ScrollTo method to scroll to a
specific position but how do I find 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, like 'stop' or
'can't scroll' or 'have only scrolled 50'. When the end of the docuument is
reached I would still be calling ScrollTo adding 200 each time to my internal
scroll position. The two would get out-of-sync.

Is there a way to read the current scroll position?
Tor Vidvei
2010-12-05 08:39:03 UTC
Permalink
You can read the scroll position from the Body element of the document by using the properties ScrollTop, ScrollLeft or ScrollRectangle. Do something like this:

Rectangle scrollRect // X,Y: Scroll position; Width,Height: Size of document

HtmlElement body = webBrowser1.Document.GetElementsByTagName("body")[0];
if (body != null) scrollRect = body.ScrollRectangle;


Tor
Post by Futronics Developer
I'm trying to do my own scrolling with the WebBrowser control (2 large
buttons next to the control).
I can use the WebBrowser.Document.Window.ScrollTo method to scroll to a
specific position but how do I find 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, like 'stop' or
'can't scroll' or 'have only scrolled 50'. When the end of the docuument is
reached I would still be calling ScrollTo adding 200 each time to my internal
scroll position. The two would get out-of-sync.
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...