TWebBrowser里网页事件是这样绑定到App里的,VB这样干,CB该怎样?
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干的, 可是在CB里怎样干啊? 各位大侠给点代码吧。
犹其想得到BCB_FANS大牛的指点,呵呵。