Getting Mousedown event in WebBrowser

vinodkris

New member
Joined
Mar 31, 2008
Messages
3
Programming Experience
3-5
Hi All,

I have one requirement where in i hava a form on which i have one WebBrowser control. I need to check the Mouse down operation user performs on the WebBrowser control I.e in the opened WebPage. Basically an event should be generated when the user performs the MouseDown/MouseClick operation. In this scenario i dont want to use Documentcompleted as i need to perform some checks before page goes in to Documentcompleted event. Please tell me how can i accompolish this since webbrowser control as such dont have MouseDown event.

Also i have tried with AxWebBrowser which has MouseClick event but while running it gives me an Innertext Exception. I came across some code snippets which deals with same kinda issue but i could not digest it completely since it involves mshtml and extensions.

Please help me solve this

Thanks
Vinod
 
What you say about DocumentCompleted I don't understand, you can't access the document until ReadyState is Complete, which is one of states that is reported in DocumentCompleted event. AttachEventHandler method of HtmlDocument is used to attach events of the document, these are Html DOM events like "onclick", "onmousedown" etc.
VB.NET:
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) _
Handles WebBrowser1.DocumentCompleted
    If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
        WebBrowser1.Document.AttachEventHandler("onclick", AddressOf wb_click)
    End If
End Sub

Sub wb_click(ByVal sender As Object, ByVal e As EventArgs)
    MsgBox(WebBrowser1.Document.ActiveElement.TagName)
End Sub
 
Hi John,

Thanks for the reply. I have already tried it but the problem i noticed are

--> It goes to the wb_click when i make click operation in the first page but if i navigated to the other page say after entering Userid and password and clicks on logon button, a new page comes. Then if i clicked on any objects in the new page it will not go to the wb_click.

--> Also the condition

If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
becomes true even if the page is refresging I.e Loading. So it gives me the tagname (as in your example) till the page has completely loaded.

I guess i need to detach the eventhandler somewhere but i am not sure about where to do it. Please tell me where should i put the same.


Thanks
Vinod
 
new page comes...it will not go
New page is a new object you need to attach to, this is done in the posted sample.

ReadyState=Complete only happens once in DocumentCompleted event for each navigation. A new navigation/refresh means you have a new document object that you have to attach to, handled as said.

Navigating event can be used to DetachEventHandler.
 
Back
Top