5 Replies - 12920 Views - Last Post: 26 October 2010 - 05:21 PM Rate Topic: -----

#1 sly9er  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 25-October 10

Force webbrowser control to scroll left/down

Posted 25 October 2010 - 08:35 PM

Here is an interesting conundrum...

Normally I can get the webbrowser control in my vb.net application to scroll using the following code after the webpage loads into the webbrowser control:
WebBrowserPageView.document.window.ScrollTo(50, 50)


But when the webpage uses the DOM to update the page after the page loads, the scroll bars will scroll for half a moment to 50,50 but then snap back to 0,0. Very frustrating.

Any ideas on how to overcome the snapback?

Is This A Good Question/Topic? 0
  • +

Replies To: Force webbrowser control to scroll left/down

#2 Jack Eagles1  Icon User is offline

  • Pugnacious Penguin (inspired by no2pencil)
  • member icon

Reputation: 183
  • View blog
  • Posts: 1,152
  • Joined: 10-December 08

Re: Force webbrowser control to scroll left/down

Posted 26 October 2010 - 03:27 AM

Can you use the DocumentCompleted event of the webbrowser to start a timer to perform that action?

Otherwise, there are a few other solutions.
Was This Post Helpful? 0
  • +
  • -

#3 sly9er  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 25-October 10

Re: Force webbrowser control to scroll left/down

Posted 26 October 2010 - 08:20 AM

I have tried DocumentCompleted as well in the two ways below. The only difference is the page that updates with the DOM never jumps to 50,50 before snapping back to 0,0. Plus it just took longer for the page to display. So I suppose that is not an option. Also tried DocumentCompleted without timer with no luck. Any other suggestions?
    Private Sub WebBrowserPageView_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowserPageView.DocumentCompleted
        'Delay
        Const OneSec As Double = 1.0# / (1440.0# * 60.0#)
        Dim dblWaitTil As Date
        Now.AddSeconds(OneSec)
        dblWaitTil = Now.AddSeconds(OneSec).AddSeconds(3)
        Do Until Now > dblWaitTil
            Application.DoEvents() ' Allow windows messages to be processed
        Loop
        WebBrowserPageView.document.window.ScrollTo(50, 50)
    End Sub

    Private Sub WebBrowserPageView_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowserPageView.DocumentCompleted
        ScrollToPoint()
    End Sub

    Private Sub ScrollToPoint()
        'Delay
        Const OneSec As Double = 1.0# / (1440.0# * 60.0#)
        Dim dblWaitTil As Date
        Now.AddSeconds(OneSec)
        dblWaitTil = Now.AddSeconds(OneSec).AddSeconds(3)
        Do Until Now > dblWaitTil
            Application.DoEvents() ' Allow windows messages to be processed
        Loop
        WebBrowserPageView.document.window.ScrollTo(50, 50)
    End Sub

Was This Post Helpful? 0
  • +
  • -

#4 Jack Eagles1  Icon User is offline

  • Pugnacious Penguin (inspired by no2pencil)
  • member icon

Reputation: 183
  • View blog
  • Posts: 1,152
  • Joined: 10-December 08

Re: Force webbrowser control to scroll left/down

Posted 26 October 2010 - 09:59 AM

Well, what you could do is get an HtmlElement in the webbrowser's document. Then you could use HtmlElemnt.ScrollIntoView(False)

This post has been edited by Jack Eagles1: 26 October 2010 - 10:00 AM

Was This Post Helpful? 0
  • +
  • -

#5 sly9er  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 25-October 10

Re: Force webbrowser control to scroll left/down

Posted 26 October 2010 - 03:58 PM

Well,

Here is what I have tried next and it didn't even respond.
    Public Sub ScrollToElement(ByVal ElemName As String)
        If WebBrowserPageView.ReadyState = WebBrowserReadyState.Complete Then
            If (WebBrowserPageView.Document IsNot Nothing) Then
                With WebBrowserPageView.Document
                    Dim Elems As HtmlElementCollection = .All.GetElementsByName(ElemName)
                    If (Not Elems Is Nothing And Elems.Count > 0) Then
                        Dim Elem As HtmlElement = Elems(0)
                        Elem.ScrollIntoView(True)
                    End If
                End With
            End If
        End If
    End Sub


Interestingly enough, I added a msgbox just to see if the element was registering, and it does, but also noticed that after I click okay on the message prompt, it does indeed scroll to the element. But I can't be putting a message prompt in there.
    Public Sub ScrollToElement(ByVal ElemName As String)
        If WebBrowserPageView.ReadyState = WebBrowserReadyState.Complete Then
msgbox(ElemName)
            If (WebBrowserPageView.Document IsNot Nothing) Then
                With WebBrowserPageView.Document
                    Dim Elems As HtmlElementCollection = .All.GetElementsByName(ElemName)
                    If (Not Elems Is Nothing And Elems.Count > 0) Then
                        Dim Elem As HtmlElement = Elems(0)
                        Elem.ScrollIntoView(True)
                    End If
                End With
            End If
        End If
    End Sub


So I replaced the msgbox with a timer, but then I get a repetive webbrowser flicker as the ScrollToElement sub cycles through all the page elements until it finally gets to the rightnavcolumn element. So frustrating.

Wondering if I should put the browser, with scroll bars disabled, inside a panel with scroll bars ENABLED. But how to get the webbrowser to go only as wide as the webpage it loads.
Was This Post Helpful? 0
  • +
  • -

#6 Jack Eagles1  Icon User is offline

  • Pugnacious Penguin (inspired by no2pencil)
  • member icon

Reputation: 183
  • View blog
  • Posts: 1,152
  • Joined: 10-December 08

Re: Force webbrowser control to scroll left/down

Posted 26 October 2010 - 05:21 PM

Yeah. I've actually noticed some weird stuff to do with some of the webbrowser events, which are incredibly frustrating. The panel thing is a nice idea, but I have tried, tried and tried again to make a webbrowser's content automatically resize, and have concluded that it's nearly impossible (well nothing's impossible). I have however been able to get an image of the web page and use resize it. I have also been able to use OLECMD Optical zoom to zoom out on a webpage, but it never really does it exactly the way you want. I've got a tutorial posted on OLECMD optical zoom, so you could incorporate that into your panel idea, and have a fiddle around with it. Good luck.

My tutorial is here: http://www.dreaminco...d-optical-zoom/

This post has been edited by Jack Eagles1: 26 October 2010 - 05:27 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1