Solved

Detect scroll to end of document in a WebBrowser control.

Posted on 2010-08-31
5
1,850 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

760 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

21 Experts available now in Live!

Get 1:1 Help Now