Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2172
  • Last Modified:

Detect scroll to end of document in a WebBrowser control.

I recently wrote an application for a customer that displayed and html file of Terms and Conditions on login, requiring the user to accept or decline.  The accept button is required to be inactive until the user scrolls to the end of the document.  This was written in C# (.Net 2.0), but the client now wants it rewritten in VB6 as many workstations are still running XP and don't have the required framework installed.  The client is one of those that requires authorisation from God in triplicate to install anything on the network, and will not commit to having the .Net framework installed (even though they told me at the outset that it would be)

The code I used to detect scroll to end required the prescence of a named <DIV> element in the html, and the method used can be seen here:

http://social.msdn.microsoft.com/Forums/en-US/vbide/thread/7b7d5300-4fcb-405d-a402-96cf99c2a7ad

I have tried to replicate this in VB6, but cannot detect the scrolling of the document.  Any ideas on how I can do it with standard MS Controls (no 3rd party dll's etc)?
0
cquinn
Asked:
cquinn
  • 3
  • 2
1 Solution
 
darbid73Commented:
Basically that code looks like it checks for the total height of the document (which is a DIV), then check for the height at scroll time.  If it gets to the hieght then they have scrolled to the bottom.

<I have tried to replicate this in VB6, but cannot detect the scrolling of the document. >

if the scroll event is not working I would suggest you check this part

Private WithEvents theDiv As mshtml.HTMLDivElement

and this part of the code


 theDiv = WebBrowser1.Document.All("theDiv").DomElement
agree.Enabled = theDiv.scrollHeight <= WebBrowser1.Height

Personally you could use the scroll event of the Webbrowser control to do the same thing.  WithOUT the need to sink events to this DIV.
       
Alternative
Why not just put the button on the HTML page - at the bottom - then they HAVE to scroll to the bottom to click it.

Onclick should try to go to a new link - then in the webbrowser controls Beforenavigate event, cancel the navigation, check the URL is the same as the link you have put on this button and then continue on with your code.
0
 
cquinnAuthor Commented:
Darbid

The webbrowser control does not appear to have a scroll event, so I am not aware of a way of doing this.

I think the scroll event of the Div is only called if there is no scroll bar on the webbrowser control - I have tried disabling the scrollbar in several different ways (it's easy in .net - there is a Scrollbars property!).  

I have already proposed the buttons in the html to the client and have it working perfectly in the way you describe, but the client wants form buttons!
0
 
darbid73Commented:
<The webbrowser control does not appear to have a scroll event, so I am not aware of a way of doing this.>
Sorry my fault I am wrong.  The VB6 form should have a MouseMove event like this

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

End Sub

<I think the scroll event of the Div is only called if there is no scroll bar on the webbrowser control - I have tried disabling the scrollbar in several different ways (it's easy in .net - there is a Scrollbars property!)>

I dont know about that.  But with the webbrowser control (as far as i know the Webbrowser control has changed very little from VB6 even in WPF it is still very similar (VB/C#/C++)).  AS I understand it the scroll bar is determined by the HTML - if you put in the body of your HTML scrollbar = none then they will go.  But it depends on your HTML.

For existing HTML from public internet sites I insert this from the Webbrowser Control into the document.  You can of course add this to your HTML which should then remove the scroll bars.

FORM.WBC.Document.body.scroll = "no"

OR

FORM.WBC.Document.all(1).Style.overflow = "hidden"

<I have already proposed the buttons in the html to the client and have it working perfectly in the way you describe, but the client wants form buttons!> More coding for you and I bet they do not want to pay for it.

Ok then lets stick with your example.  I must say I have NEVER used the DIV like this, but I have done it simply with the whole HTMLDocument.

Something like

1.  I think to get the HTMLDocument from the Webbrowser - eg this here theDiv = WebBrowser1.Document.All("theDiv").DomElement
you will have to use the DocumentComplete event of the Webbrowser Control.  Something like


Private Sub wb_leo_DocumentComplete(ByVal pDisp As Object, URL As Variant)

Dim myHTMLDoc As HTMLDocument

Set myHTMLDoc = FORM.WBC.Document

DocHeight = myHTMLDoc.Document.body.scrollHeight

set myHTML = nothing

end sub

2.  Then in the mouse event add the scrolls Y value to another variable until they get close to DocHeight.

I am not good working in theory, maybe have a go and show some code.
0
 
darbid73Commented:
by the way.  I just recently had to agree to some Terms and Conditions and I had to wait 60 seconds.

I got bored after I 10 seconds and actually read part of it. :-)

scrolling to the bottom can be done in 1 second.

Neither guarantees reading, but putting a timer on the form to show the button control after X seconds is is way easy to code.
0
 
cquinnAuthor Commented:
The client has gone for the buttons being active all the time - thanks for your input - the timer idea is quite good
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now