请教ole中调用的网页控件问题
2016-02-05 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517181
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
这个问题我今天又研究了一下,仍然没有解决,下面是其他的一些例子。lz可以参考其思路,共同研究:
vb的
VB code程序中如何监控网页中元素的事件
对编写脚本熟悉的读者都知道页面中可以添加脚本响应元素的事件,例如超链接的OnClick事件,图片的OnMouseMove事件,我们也可以使VB程序响应这些事件。下面是一个VB响应页面中按钮的Click事件的代码:
首先建立一个新工程,在Form1中加入一个Webbrowser控件,然后在Form1中加入以下代码:
Option Explicit
Public Sub Some_Procedure()
MsgBox "你点击了按钮."
End Sub
Private Sub Form_Load()
'下载空页面
WebBrowser1.Navigate2 "about:blank"
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
'建立事件响应类
Dim cfForward As clsForward
'定义在浏览器中显示的HTML代码,其中包含一个按钮btnMyButton
Dim sHTML As String
sHTML = "<P>This is some text.</P>"
sHTML = sHTML & "<P>And here is a button.</P>"
sHTML = sHTML & "<BUTTON ID=btnMyButton>"
sHTML = sHTML & "Click this button.</BUTTON>"
'将HTML代码写入浏览器
WebBrowser1.Document.body.innerHTML = sHTML
'将事件响应类连接到页面的按钮btnMyButton上
Set cfForward = New clsForward
cfForward.Set_Destination Me, "Some_Procedure"
WebBrowser1.Document.All("btnMyButton").onclick = cfForward
End Sub
向工程中添加一个Class Module,Class Module的Name属性设定为clsForward,在clsForward中添加以下代码:
Option Explicit
Dim oObject As Object
Dim sMethod As String
Dim bInstantiated As Boolean
Private Sub Class_Initialize()
bInstantiated = False
End Sub
Public Sub Set_Destination(oInObject As Object, sInMethod As String)
Set oObject = oInObject
sMethod = sInMethod
bInstantiated = True
End Sub
Public Sub My_Default_Method()
If bInstantiated Then
CallByName oObject, sMethod, VbMethod
End If
End Sub
运行程序,点击Webbrowser中的“Click this button”按钮。程序就会弹出消息框提示“你点击了按钮.”
vb的
VB code程序中如何监控网页中元素的事件
对编写脚本熟悉的读者都知道页面中可以添加脚本响应元素的事件,例如超链接的OnClick事件,图片的OnMouseMove事件,我们也可以使VB程序响应这些事件。下面是一个VB响应页面中按钮的Click事件的代码:
首先建立一个新工程,在Form1中加入一个Webbrowser控件,然后在Form1中加入以下代码:
Option Explicit
Public Sub Some_Procedure()
MsgBox "你点击了按钮."
End Sub
Private Sub Form_Load()
'下载空页面
WebBrowser1.Navigate2 "about:blank"
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
'建立事件响应类
Dim cfForward As clsForward
'定义在浏览器中显示的HTML代码,其中包含一个按钮btnMyButton
Dim sHTML As String
sHTML = "<P>This is some text.</P>"
sHTML = sHTML & "<P>And here is a button.</P>"
sHTML = sHTML & "<BUTTON ID=btnMyButton>"
sHTML = sHTML & "Click this button.</BUTTON>"
'将HTML代码写入浏览器
WebBrowser1.Document.body.innerHTML = sHTML
'将事件响应类连接到页面的按钮btnMyButton上
Set cfForward = New clsForward
cfForward.Set_Destination Me, "Some_Procedure"
WebBrowser1.Document.All("btnMyButton").onclick = cfForward
End Sub
向工程中添加一个Class Module,Class Module的Name属性设定为clsForward,在clsForward中添加以下代码:
Option Explicit
Dim oObject As Object
Dim sMethod As String
Dim bInstantiated As Boolean
Private Sub Class_Initialize()
bInstantiated = False
End Sub
Public Sub Set_Destination(oInObject As Object, sInMethod As String)
Set oObject = oInObject
sMethod = sInMethod
bInstantiated = True
End Sub
Public Sub My_Default_Method()
If bInstantiated Then
CallByName oObject, sMethod, VbMethod
End If
End Sub
运行程序,点击Webbrowser中的“Click this button”按钮。程序就会弹出消息框提示“你点击了按钮.”
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询