如何只在自己的窗体中用vb webbrowser打开网页

2024-11-28 01:12:06
推荐回答(2个)
回答(1):

有两种方法。一种是还是在原来的窗口上打开。另一种是新窗口上打开。

代码如下:

1.原来的窗口
Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
Cancel = True
WebBrowser1.Navigate2 WebBrowser1.Document.activeElement.href
End Sub

2.新窗口
Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
Dim NFrm As New Form1
NFrm.WebBrowser1.RegisterAsBrowser = True
Set ppDisp = NFrm.WebBrowser1.Object
NFrm.Visible = True
End Sub

回答(2):

Private Sub Command1_Click()
WebBrowser1.Navigate "baidu.com"
End Sub
莫非还有更复杂的打开方法???我只知道这一种``