Problem handling events with web browser control

  • Thread starter Thread starter Reid
  • Start date Start date
R

Reid

I have a Catch-22 type problem with the web browser control in VB Dot Net.

I can have complete functionality on a web page in the control. But as soon
as I add event handlers to the vb app (e.g. onclick event) , the behavior of
the web page in the control changes drastically. Input boxes will not
accept the focus. No data can be entered. As soon as the event handler is
removed and the app recompiled, functionality is restored.

The idea, of course, is to access the control programatically from vb.
However, I am being thwarted somewhare along the way. I don't know whether
it's by design or whether I have made the wrong declarations somewhere in
the code...

This programming technique works splendidly in VB6. I am just unable to
port it to dot net.

Any suggestions or insight would be appreciated.

Thanks,

Reid
 
I tried the example but am still having the same problem.

The example uses microsoft's web site as its illustrative page.
Unfortunately, the app does not allow anything to be entered in the search
field (INPUT type=text) or even to accept the focus. So I'm right back
where I started.

Any ideas?

Thanks,

Reid
 
Reid

Create a class that implements HTMLDocumentEvents2 (say, DocumentEvents2).
For default behaviour return True from each of the functions.

Then call the following function from the DocumentComplete event handler.

<code>
Private Sub EnableDocEvents()

Dim icp As UCOMIConnectionPoint
Dim icpc As UCOMIConnectionPointContainer
Dim g As Guid

g = GetType(mshtml.HTMLDocumentEvents2).GUID

icpc = DirectCast(Document, UCOMIConnectionPointContainer)

icpc.FindConnectionPoint(g, icp)

If m_DocEvents2Cookie <> -1 Then
icp.Unadvise(m_DocEvents2Cookie)

m_DocEvents2Cookie = -1
End If

m_DocumentEvents2 = New DocumentEvents2(Me)

icp.Advise(m_DocumentEvents2, m_DocEvents2Cookie)

' Wait until the browser has settled before returning
WaitReady()

End Sub
</code>

m_DocEvents2Cookie is a module level private integer, initialised to -1.

Declare m_DocumentEvents2 WithEvents As DocumentEvents2 at module level as
well.

As I say, this is a known problem, and depending on what you want to achieve
you need to go to increasing lengths to overcome it.

HTH

Charles
 
Back
Top