Solved

Detect scroll to end of document in a WebBrowser control.

Posted on 2010-08-31
5
1,869 Views
Last Modified: 2012-05-10
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
Comment
Question by:cquinn
  • 3
  • 2
5 Comments
 
LVL 19

Expert Comment

by:darbid73
ID: 33565895
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
 
LVL 15

Author Comment

by:cquinn
ID: 33566195
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
 
LVL 19

Expert Comment

by:darbid73
ID: 33566377
<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
 
LVL 19

Accepted Solution

by:
darbid73 earned 250 total points
ID: 33575125
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
 
LVL 15

Author Closing Comment

by:cquinn
ID: 33576469
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now