Private Sub Form_Load() WebBrowser1.Navigate "www.baidu.com" End Sub Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean) Dim nStr As String nStr = URL If Left(nStr, 8) <> "mouse://" Then Exit Sub '让网页正常跳转
Cancel = True '让网页不要跳转 Dim nMouse As String, x As Long, y As Long, S As Long nStr = Mid(nStr, 9) S = InStr(nStr, "|") nMouse = Left(nStr, S - 1): nStr = Mid(nStr, S + 1) S = InStr(nStr, "|") x = Val(Left(nStr, S - 1)): y = Val(Mid(nStr, S + 1)) Me.Caption = x & " " & y '显示鼠标捕获的状态 End SubPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant) On Error Resume Next Dim js As String js = "document.body.onmousemove=function()" & vbCrLf & _ "{location.href='mouse://move|'+window.event.x + '|'+window.event.y;}" WebBrowser1.Document.parentWindow.execScript js, "javascript" End Sub
请朋友帮我写鸽如上图源码!鼠标坐标只显示在picture控件里的,感激不尽
WebBrowser1.Navigate "www.baidu.com"
End Sub
Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
Dim nStr As String
nStr = URL
If Left(nStr, 8) <> "mouse://" Then Exit Sub '让网页正常跳转
Cancel = True '让网页不要跳转
Dim nMouse As String, x As Long, y As Long, S As Long
nStr = Mid(nStr, 9)
S = InStr(nStr, "|")
nMouse = Left(nStr, S - 1): nStr = Mid(nStr, S + 1)
S = InStr(nStr, "|")
x = Val(Left(nStr, S - 1)): y = Val(Mid(nStr, S + 1))
Me.Caption = x & " " & y '显示鼠标捕获的状态
End SubPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
On Error Resume Next
Dim js As String
js = "document.body.onmousemove=function()" & vbCrLf & _
"{location.href='mouse://move|'+window.event.x + '|'+window.event.y;}"
WebBrowser1.Document.parentWindow.execScript js, "javascript"
End Sub
这个很模糊 是想要在webbrowser里实时更新鼠标的坐标呢 还是按个按钮后更新呢
webbrowser当前浏览的页面上有显示坐标的位置么
这么问问题叫人怎么回答