Form1.vb
上传用户:bjsjyd6688
上传日期:2022-06-03
资源大小:198k
文件大小:13k
- Public Class Form1
- Dim i As Integer = 1
- Private Enum Exec
- OLECMDID_OPTICAL_ZOOM = 63
- End Enum
- Private Enum ExecOpt
- OLECMDEXECOPT_DODEFAULT = 0
- OLECMDEXECOPT_PROMPTUSER = 1
- OLECMDEXECOPT_DONTPROMPTUSER = 2
- OLECMDEXECOPT_SHOWHELP = 3
- End Enum
- #Region "Subroutines"
- Public Sub OpenTab()
- Dim wb As New WebBrowser
- wb.Name = "wb"
- wb.Dock = DockStyle.Fill
- Dim tp As New TabPage
- tp.ImageIndex = 0
- tp.Text = "Untitled"
- TabControl1.TabPages.Add(tp)
- TabControl1.SelectTab(i - 1)
- TabControl1.SelectedTab.Controls.Add(wb)
- CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate("http://www.google.com.sg/")
- AddHandler wb.DocumentCompleted, AddressOf wb_DocumentCompleted
- AddHandler wb.StatusTextChanged, AddressOf wb_StatusTextChanged
- AddHandler wb.Navigating, AddressOf wb_Navigating
- AddHandler wb.Navigated, AddressOf wb_Navigated
- AddHandler wb.CanGoBackChanged, AddressOf wb_CGB
- AddHandler wb.CanGoForwardChanged, AddressOf wb_CGF
- AddHandler wb.NewWindow, AddressOf wb_NewWindow
- i = i + 1
- End Sub
- Public Sub CloseTab()
- If TabControl1.TabPages.Count = 1 Then
- End
- Else
- TabControl1.TabPages.RemoveAt(TabControl1.SelectedIndex)
- TabControl1.SelectTab(TabControl1.TabPages.Count - 1)
- i = i - 1
- End If
- End Sub
- #End Region
- #Region "Buttons"
- Private Sub OpenTabToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenTabToolStripMenuItem.Click
- OpenTab()
- End Sub
- Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
- CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).GoBack()
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentCompleted, AddressOf wb_DocumentCompleted
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).StatusTextChanged, AddressOf wb_StatusTextChanged
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigating, AddressOf wb_Navigating
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).CanGoBackChanged, AddressOf wb_CGB
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).CanGoForwardChanged, AddressOf wb_CGF
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigated, AddressOf wb_Navigated
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).NewWindow, AddressOf wb_NewWindow
- End Sub
- Private Sub btnForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForward.Click
- CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).GoForward()
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentCompleted, AddressOf wb_DocumentCompleted
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).StatusTextChanged, AddressOf wb_StatusTextChanged
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigating, AddressOf wb_Navigating
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).CanGoBackChanged, AddressOf wb_CGB
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).CanGoForwardChanged, AddressOf wb_CGF
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigated, AddressOf wb_Navigated
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).NewWindow, AddressOf wb_NewWindow
- End Sub
- Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
- CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Refresh()
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentCompleted, AddressOf wb_DocumentCompleted
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).StatusTextChanged, AddressOf wb_StatusTextChanged
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigating, AddressOf wb_Navigating
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).CanGoBackChanged, AddressOf wb_CGB
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).CanGoForwardChanged, AddressOf wb_CGF
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigated, AddressOf wb_Navigated
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).NewWindow, AddressOf wb_NewWindow
- End Sub
- Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
- CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Stop()
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentCompleted, AddressOf wb_DocumentCompleted
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).StatusTextChanged, AddressOf wb_StatusTextChanged
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigating, AddressOf wb_Navigating
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).CanGoBackChanged, AddressOf wb_CGB
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).CanGoForwardChanged, AddressOf wb_CGF
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigated, AddressOf wb_Navigated
- AddHandler CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).NewWindow, AddressOf wb_NewWindow
- End Sub
- Private Sub btnNav_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNav.Click
- CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(cboURL.Text)
- End Sub
- Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
- CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate("http://www.google.com/search?q=" & cboSearch.Text)
- cboSearch.Items.Add(cboSearch.Text)
- End Sub
- Private Sub CloseTabToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseTabToolStripMenuItem.Click
- CloseTab()
- End Sub
- Private Sub OpenTabToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenTabToolStripMenuItem1.Click
- OpenTab()
- End Sub
- Private Sub CloseTabToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseTabToolStripMenuItem1.Click
- CloseTab()
- End Sub
- Private Sub QuitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuitToolStripMenuItem.Click
- End
- End Sub
- #End Region
- #Region "Events"
- Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
- OpenTab()
- End Sub
- Private Sub wb_DocumentCompleted(ByVal sender As Object, ByVal e As Windows.Forms.WebBrowserDocumentCompletedEventArgs)
- cboURL.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Url.ToString
- cboURL.Items.Add(CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Url.ToString)
- End Sub
- Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
- Try
- cboURL.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Tag
- Catch ex As Exception
- cboURL.Text = "About:Blank"
- End Try
- Try
- Me.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle & " - Tabbed Browser"
- Catch ex As Exception
- Me.Text = "Untitled - Tabbed Browser"
- End Try
- End Sub
- Private Sub wb_StatusTextChanged()
- lblStatus.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).StatusText
- End Sub
- Private Sub wb_Navigating()
- TabControl1.SelectedTab.Text = "Loading..."
- btnRefresh.Enabled = False
- btnStop.Enabled = True
- End Sub
- Private Sub wb_CGB()
- If CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).CanGoBack = True Then
- btnBack.Enabled = True
- Else
- btnBack.Enabled = False
- End If
- End Sub
- Private Sub wb_CGF()
- If CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).CanGoForward = True Then
- btnForward.Enabled = True
- Else
- btnForward.Enabled = False
- End If
- End Sub
- Private Sub wb_Navigated()
- If CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle = "" Then
- Me.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Url.ToString & " - Tabbed Browser"
- Else
- Me.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle & " - Tabbed Browser"
- End If
- If CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle = "" Then
- TabControl1.SelectedTab.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Url.ToString
- Else
- TabControl1.SelectedTab.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle
- End If
- CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Tag = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Url.ToString
- btnRefresh.Enabled = True
- btnStop.Enabled = False
- End Sub
- Private Sub cboURL_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cboURL.KeyUp
- If e.KeyCode = Keys.Enter Then
- CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(cboURL.Text)
- End If
- End Sub
- Private Sub cboSearch_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cboSearch.KeyDown
- If e.KeyCode = Keys.Enter Then
- CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate("http://www.google.com/search?q=" & cboSearch.Text)
- cboSearch.Items.Add(cboSearch.Text)
- End If
- End Sub
- #End Region
- Private Sub InToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- Try
- Dim Res As Object = Nothing
- Dim MyWeb As Object
- MyWeb = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).ActiveXInstance
- MyWeb.ExecWB(Exec.OLECMDID_OPTICAL_ZOOM, _
- ExecOpt.OLECMDEXECOPT_PROMPTUSER, 150%, IntPtr.Zero)
- Catch ex As Exception
- End Try
- End Sub
- Private Sub OutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- Try
- Dim Res As Object = Nothing
- Dim MyWeb As Object
- MyWeb = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).ActiveXInstance
- MyWeb.ExecWB(Exec.OLECMDID_OPTICAL_ZOOM, _
- ExecOpt.OLECMDEXECOPT_PROMPTUSER, 50%, IntPtr.Zero)
- Catch ex As Exception
- End Try
- End Sub
- Private Sub NormalToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- Try
- Dim Res As Object = Nothing
- Dim MyWeb As Object
- MyWeb = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).ActiveXInstance
- MyWeb.ExecWB(Exec.OLECMDID_OPTICAL_ZOOM, _
- ExecOpt.OLECMDEXECOPT_PROMPTUSER, 100%, IntPtr.Zero)
- Catch ex As Exception
- End Try
- End Sub
- Private Sub wb_NewWindow()
- End Sub
- Private Sub CloseWindowToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseWindowToolStripMenuItem.Click
- Me.Close()
- End Sub
- Private Sub OpenWindowToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenWindowToolStripMenuItem.Click
- Dim frm As New Form1
- frm.Show()
- End Sub
- Private Sub OpenFileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenFileToolStripMenuItem.Click
- Try
- ofd.ShowDialog()
- CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(ofd.FileName)
- Catch ex As Exception
- MessageBox.Show(ex.Message, "Error - Tabbed Browser", MessageBoxButtons.OK, MessageBoxIcon.Error)
- End Try
- End Sub
- End Class