I need to be able to click on a WebBrowser control to do something, but it doesn't have a Click event. Any ideas how I could do such a thing?
Printable View
I need to be able to click on a WebBrowser control to do something, but it doesn't have a Click event. Any ideas how I could do such a thing?
Here is the code to input text into a browsers textbox. (where it has Textbox1.Text you put your own text)
Here is the code to click on a specific button in the browser.Code:WebBrowser1.Document.GetElementById("TextBoxIDGoesHere").SetAttribute("value", TextBox1.Text)
Note: These codes are for a built-in web browser meaning you have a web browser as part of your program.Code:WebBrowser1.Document.GetElementById("ButtonsIDGoesHere").InvokeMember("click")
The WebBrowser will send WM_PARENTNOTIFY messages. You can capture these in an inherited WebBrowser control and determine whether they are mouse messages:
Code:Public Class ClickableWebBrowser
Inherits WebBrowser
'//constants
Private Const WM_PARENTNOTIFY As Integer = &H210
Private Const WM_LBUTTONDOWN As Integer = &H201
Private Const WM_RBUTTONDOWN As Integer = &H204
'//events
Public Shadows Event MouseDown As MouseEventHandler
'//methods
Private Function CreateMouseEventArgs(ByVal button As MouseButtons, _
ByVal location As Point) As MouseEventArgs
Return New MouseEventArgs(button, 0, location.X, location.Y, 0)
End Function
Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
RaiseEvent MouseDown(Me, e)
End Sub
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = ClickableWebBrowser.WM_PARENTNOTIFY Then
Select Case m.WParam.ToInt32()
Case ClickableWebBrowser.WM_LBUTTONDOWN
Me.OnMouseDown(Me.CreateMouseEventArgs(MouseButtons.Left, _
New Point(m.LParam.ToInt32())))
Case ClickableWebBrowser.WM_RBUTTONDOWN
Me.OnMouseDown(Me.CreateMouseEventArgs(MouseButtons.Right, _
New Point(m.LParam.ToInt32())))
End Select
End If
MyBase.WndProc(m)
End Sub
End Class
FA ... thats exactly what I need it works great. Now how would I add MouseEnter & MouseLeave events?
You can subscribe to the events of the HtmlDocument that the WebBrowser.Document property returns. Here are the events.
FA ... I'm not sure the HtmlDocuments events will work for me. Is it possible to add the mouse enter & leave events the same way you added the MouseDown event above?