當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET WebBrowser.Navigate方法代碼示例

本文整理匯總了VB.NET中System.Windows.Forms.WebBrowser.Navigate方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET WebBrowser.Navigate方法的具體用法?VB.NET WebBrowser.Navigate怎麽用?VB.NET WebBrowser.Navigate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Windows.Forms.WebBrowser的用法示例。


在下文中一共展示了WebBrowser.Navigate方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: Navigate

' Navigates to the URL in the address box when 
' the ENTER key is pressed while the ToolStripTextBox has focus.
Private Sub toolStripTextBox1_KeyDown( _
    ByVal sender As Object, ByVal e As KeyEventArgs) _
    Handles toolStripTextBox1.KeyDown

    If (e.KeyCode = Keys.Enter) Then
        Navigate(toolStripTextBox1.Text)
    End If

End Sub

' Navigates to the URL in the address box when 
' the Go button is clicked.
Private Sub goButton_Click( _
    ByVal sender As Object, ByVal e As EventArgs) _
    Handles goButton.Click

    Navigate(toolStripTextBox1.Text)

End Sub

' Navigates to the given URL if it is valid.
Private Sub Navigate(ByVal address As String)

    If String.IsNullOrEmpty(address) Then Return
    If address.Equals("about:blank") Then Return
    If Not address.StartsWith("http://") And _
        Not address.StartsWith("https://") Then
        address = "http://" & address
    End If

    Try
        webBrowser1.Navigate(New Uri(address))
    Catch ex As System.UriFormatException
        Return
    End Try

End Sub

' Updates the URL in TextBoxAddress upon navigation.
Private Sub webBrowser1_Navigated(ByVal sender As Object, _
    ByVal e As WebBrowserNavigatedEventArgs) _
    Handles webBrowser1.Navigated

    toolStripTextBox1.Text = webBrowser1.Url.ToString()

End Sub
開發者ID:VB.NET開發者,項目名稱:System.Windows.Forms,代碼行數:48,代碼來源:WebBrowser.Navigate

示例2: WebBrowserDemo

' 導入命名空間
Imports System.Windows.Forms

public class WebBrowserDemo
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
Public Class Form1

    Private Sub txtURL_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtURL.KeyDown
        If (e.KeyCode = Keys.Enter) Then
            WebBrowser1.Navigate(txtURL.Text)
        End If
    End Sub

    Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
        WebBrowser1.GoBack()
    End Sub

    Private Sub btnForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForward.Click
        WebBrowser1.GoForward()
    End Sub

    Private Sub btnHome_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHome.Click
        WebBrowser1.GoHome()
    End Sub
End Class
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.ToolStrip1 = New System.Windows.Forms.ToolStrip
        Me.ToolStripLabel1 = New System.Windows.Forms.ToolStripLabel
        Me.txtURL = New System.Windows.Forms.ToolStripTextBox
        Me.btnBack = New System.Windows.Forms.ToolStripButton
        Me.btnForward = New System.Windows.Forms.ToolStripButton
        Me.btnHome = New System.Windows.Forms.ToolStripButton
        Me.WebBrowser1 = New System.Windows.Forms.WebBrowser
        Me.ToolStrip1.SuspendLayout()
        Me.SuspendLayout()

        Me.ToolStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripLabel1, Me.txtURL, Me.btnBack, Me.btnForward, Me.btnHome})
        Me.ToolStrip1.Location = New System.Drawing.Point(0, 0)
        Me.ToolStrip1.Size = New System.Drawing.Size(703, 25)

        Me.ToolStripLabel1.Size = New System.Drawing.Size(50, 22)
        Me.ToolStripLabel1.Text = "Address:"

        Me.txtURL.Size = New System.Drawing.Size(200, 25)

        Me.btnBack.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text
        Me.btnBack.ImageTransparentColor = System.Drawing.Color.Magenta
        Me.btnBack.Name = "btnBack"
        Me.btnBack.Size = New System.Drawing.Size(33, 22)
        Me.btnBack.Text = "Back"
        '
        'btnForward
        '
        Me.btnForward.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text
        Me.btnForward.ImageTransparentColor = System.Drawing.Color.Magenta
        Me.btnForward.Name = "btnForward"
        Me.btnForward.Size = New System.Drawing.Size(51, 22)
        Me.btnForward.Text = "Forward"
        '
        'btnHome
        '
        Me.btnHome.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text
        Me.btnHome.ImageTransparentColor = System.Drawing.Color.Magenta
        Me.btnHome.Name = "btnHome"
        Me.btnHome.Size = New System.Drawing.Size(38, 22)
        Me.btnHome.Text = "Home"
        '
        'WebBrowser1
        '
        Me.WebBrowser1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.WebBrowser1.Location = New System.Drawing.Point(0, 25)
        Me.WebBrowser1.MinimumSize = New System.Drawing.Size(20, 20)
        Me.WebBrowser1.Name = "WebBrowser1"
        Me.WebBrowser1.Size = New System.Drawing.Size(703, 429)
        Me.WebBrowser1.TabIndex = 1
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(703, 454)
        Me.Controls.Add(Me.WebBrowser1)
        Me.Controls.Add(Me.ToolStrip1)
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "MyBrowser"
        Me.ToolStrip1.ResumeLayout(False)
        Me.ToolStrip1.PerformLayout()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents ToolStrip1 As System.Windows.Forms.ToolStrip
    Friend WithEvents WebBrowser1 As System.Windows.Forms.WebBrowser
    Friend WithEvents ToolStripLabel1 As System.Windows.Forms.ToolStripLabel
    Friend WithEvents txtURL As System.Windows.Forms.ToolStripTextBox
    Friend WithEvents btnBack As System.Windows.Forms.ToolStripButton
    Friend WithEvents btnForward As System.Windows.Forms.ToolStripButton
    Friend WithEvents btnHome As System.Windows.Forms.ToolStripButton

End Class
開發者ID:VB程序員,項目名稱:System.Windows.Forms,代碼行數:108,代碼來源:WebBrowser.Navigate


注:本文中的System.Windows.Forms.WebBrowser.Navigate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。