webbrowser html events vs.2005

greetings,

this code works for vs.2003, how is this done with vs.2005 beta 2?

Dim doc As mshtml.HTMLDocument = DirectCast(webBrowser1.Document, mshtml.HTMLDocument)

' Cast to the interface that defines the event you're interested in

Dim docevents As mshtml.HTMLDocumentEvents2_Event = DirectCast(doc, mshtml.HTMLDocumentEvents2_Event)

' Define a handler to the onclick event

AddHandler docevents.onclick, AddressOf onclickproc

'Dim docevents As mshtml.HTMLDocumentEvents2_Event = webBrowser1.Document.DomDocument.mshtmlDocumentClass.IhtmlDocument5.onfocusout

AddHandler docevents, AddressOf onclickproc

Need to capture some htmldocument events. The above code works for VS.2003 but not for VS.2005 beta 2. I’ve tried various changes- like changing document to domdocument. I can examine the webbroswer1 object in debug and can see the “webBrowser1.Document.DomDocument.mshtmlDocumentClass.IhtmlDocument5.onfocusout”but can not hook my event handler to it.

Any help would be appreciataed.

[2961 byte] By [jSchultzMSDN] at [2007-12-16]
# 1
Are you using the new WebBrowser control in VS2005? This new control wraps the AxWebBrowser control that was available in VS2003.

See the help file for the events available on HtmlDocument, but here is how you would add a handler for the HtmlDocument.Click event.



Dim htmlDoc As HtmlDocument

htmlDoc = WebBrowser1.Document

AddHandler htmlDoc.Click, AddressOf htmlDoc_Click



I'm not sure I've gotten the crux of your question, though...

durstin at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2
Thanks so much. Yes, I'm a newbie and did various searches but none worked.
The event I needed was on field focus out. Modified the above to handle this and it works.

The latest I found was :

Dim doc As mshtml.HTMLWindow2Class = CType(webBrowser1.Document.Window.DomWindow, mshtml.HTMLWindow2Class)Dim DOM As mshtml.IHTMLDocument5 = CType(doc.document, mshtml.IHTMLDocument5)
AddHandler DOM.onfocusout, AddressOf focusOutSub

It broke on onfocusout not being a DOC5 event. Not sure why I could not find your solution, but everything pointed to DOC5 events.

jasMSDN at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 3
I suspect the problems you were seeing are because you are treating a WebBrowser control like an AxWebBrowser control, and it is not.
durstin at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 4
durstin,

any idea why fromElement is nothing. docs indicate that this should contain the element that was navigated from. the toElement is populated but that doen't help to know where it came from and ultimately retrieve fromElement properties (like the value of a text input field).

tia

jas

jasMSDN at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 5
Er, no. But I can try to find out. Looks like a bug...
durstin at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 6

Use both LosingFocus and Focusing. Curiously, LosingFocus has the ToElement, and Focusing has from FromElement. Focusing fires after LosingFocus (at least in my little test).

durstin at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 7
Hi Guys,
I need to find a way to trap "NavigateError" event while I have been using the Forms.WebBrowser class of 2005-Beta. Can anybody please help me in this matter? I have been despirately looking forward to your help.
Thanks,
Sohail.
SohailAslam at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 8
Sohail - did you ever find how to handle that event? I have the same problem.....
ALFKI at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...