Public Class Form1
Dim time As Integer = 0
Private Sub Form1_Load(ByVal sender As Object,ByVal e As System.EventArgs) Handles Me.Load
Me.WebBrowser1.Navigate("http://www.baidu.com")
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object,ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Select Case time
Case 0
' wd为baidu中输入搜索内容的标志,注意搜索按钮触发的方法
Me.WebBrowser1.Document.All("wd").SetAttribute("value","奥运")
Me.WebBrowser1.Document.Forms(0).InvokeMember("submit")
time += 1
End Select
End Sub
Private Sub WebBrowser1_NewWindow(ByVal sender As Object,ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow
'点击链接时,禁止打开新窗体。
e.Cancel = True
'此时转向自身窗体。 Me.WebBrowser1.Navigate(CType(sender,WebBrowser).StatusText) End Sub End Class
原文链接:https://www.f2er.com/vb/259705.html