WebBrowser.Navigate 方法

定義

將指定位置處的文件載入至 WebBrowser 控制項。Loads the document at the specified location into the WebBrowser control.

多載

Navigate(Uri, String, Byte[], String)

將指定的 Uri 所表示之位置處的文件載入至 WebBrowser 控制項,要求的方式是使用指定的 HTTP 資料,並使用指定的名稱來取代網頁框架的內容。Loads the document at the location indicated by the specified Uri into the WebBrowser control, requesting it using the specified HTTP data and replacing the contents of the Web page frame with the specified name.

Navigate(String, String, Byte[], String)

將指定的統一資源定位器 (URL) 處的文件載入至 WebBrowser 控制項,要求的方式是使用指定的 HTTP 資料,並使用指定的名稱來取代網頁框架的內容。Loads the document at the specified Uniform Resource Locator (URL) into the WebBrowser control, requesting it using the specified HTTP data and replacing the contents of the Web page frame with the specified name.

Navigate(Uri, Boolean)

將指定的 Uri 所表示之位置處的文件載入至新瀏覽器視窗或 WebBrowser 控制項。Loads the document at the location indicated by the specified Uri into a new browser window or into the WebBrowser control.

Navigate(Uri, String)

將指定的 Uri 所表示之位置處的文件載入至 WebBrowser 控制項,會使用指定的名稱來取代網頁框架的內容。Loads the document at the location indicated by the specified Uri into the WebBrowser control, replacing the contents of the Web page frame with the specified name.

Navigate(String, Boolean)

將指定的統一資源定位器 (URL) 處的文件載入至新瀏覽器視窗或 WebBrowser 控制項。Loads the document at the specified Uniform Resource Locator (URL) into a new browser window or into the WebBrowser control.

Navigate(String, String)

將指定之統一資源定位器 (URL) 處的文件載入至 WebBrowser 控制項,會使用指定的名稱來取代網頁框架的內容。Loads the document at the specified Uniform Resource Locator (URL) into the WebBrowser control, replacing the contents of the Web page frame with the specified name.

Navigate(Uri)

將指定的 Uri 所表示之位置處的文件載入至 WebBrowser 控制項,會取代前一份文件。Loads the document at the location indicated by the specified Uri into the WebBrowser control, replacing the previous document.

Navigate(String)

將指定之統一資源定位器 (URL) 處的文件載入至 WebBrowser 控制項,會取代前一份文件。Loads the document at the specified Uniform Resource Locator (URL) into the WebBrowser control, replacing the previous document.

Navigate(Uri, String, Byte[], String)

將指定的 Uri 所表示之位置處的文件載入至 WebBrowser 控制項,要求的方式是使用指定的 HTTP 資料,並使用指定的名稱來取代網頁框架的內容。Loads the document at the location indicated by the specified Uri into the WebBrowser control, requesting it using the specified HTTP data and replacing the contents of the Web page frame with the specified name.

public:
 void Navigate(Uri ^ url, System::String ^ targetFrameName, cli::array <System::Byte> ^ postData, System::String ^ additionalHeaders);
public void Navigate (Uri url, string targetFrameName, byte[] postData, string additionalHeaders);
member this.Navigate : Uri * string * byte[] * string -> unit
Public Sub Navigate (url As Uri, targetFrameName As String, postData As Byte(), additionalHeaders As String)

參數

url
Uri

Uri,代表要載入之文件的 URL。A Uri representing the URL of the document to load.

targetFrameName
String

在其中載入文件的框架名稱。The name of the frame in which to load the document.

postData
Byte[]

HTTP POST 資料 (例如表單資料)。HTTP POST data such as form data.

additionalHeaders
String

要加入預設標頭的 HTTP 標頭。HTTP headers to add to the default headers.

例外狀況

這個 WebBrowser 執行個體已不再有效。This WebBrowser instance is no longer valid.

無法從基礎 ActiveX IWebBrowser2 控制項中擷取 WebBrowser 介面實作的參考。A reference to an implementation of the IWebBrowser2 interface could not be retrieved from the underlying ActiveX WebBrowser control.

url 參數值並非代表絕對 URI。The url parameter value does not represent an absolute URI. 如需詳細資訊,請參閱IsAbsoluteUriFor more information, see IsAbsoluteUri.

備註

WebBrowser控制項會維護流覽會話期間所造訪之所有網頁的歷程記錄清單。The WebBrowser control maintains a history list of all the Web pages visited during a browsing session. 當您呼叫這個多載時,控制項會將位於 WebBrowser 指定 URI 的檔載入至具有指定之名稱的網頁框架,並將 URI 新增至歷程記錄清單的結尾。When you call this overload, the WebBrowser control loads the document at the specified URI into the Web page frame with the specified name, and adds the URI to the end of the history list. 如果指定的框架名稱無效,則會將檔載入至新的 Internet Explorer 視窗。If the frame name specified is invalid, the document is loaded into a new Internet Explorer window.

使用 GoBack 方法,將控制項傳回至導覽歷程記錄中的前一頁。Use the GoBack method to return the control to a previous page in the navigation history. 導覽後,請使用 GoForward 方法在流覽歷程記錄中返回較新的頁面。Use the GoForward method to return to a later page in the navigation history after navigating backward.

WebBrowser控制項會將最近造訪過的網站中的網頁儲存在本機硬碟上的快取中。The WebBrowser control stores Web pages from recently visited sites in a cache on the local hard disk. 每個頁面都可以指定到期日,指出它會保留在快取中的時間長度。Each page can specify an expiration date indicating how long it will remain in the cache. 當控制項流覽至頁面時,它會藉由顯示快取版本(如果有的話)來節省時間,而不是再次下載頁面。When the control navigates to a page, it saves time by displaying a cached version, if one is available, rather than downloading the page again. 使用 Refresh 方法 WebBrowser ,藉由下載來強制控制項重載目前的網頁,以確保控制項顯示最新版本。Use the Refresh method to force the WebBrowser control to reload the current page by downloading it, ensuring that the control displays the latest version.

另請參閱

適用於

Navigate(String, String, Byte[], String)

將指定的統一資源定位器 (URL) 處的文件載入至 WebBrowser 控制項,要求的方式是使用指定的 HTTP 資料,並使用指定的名稱來取代網頁框架的內容。Loads the document at the specified Uniform Resource Locator (URL) into the WebBrowser control, requesting it using the specified HTTP data and replacing the contents of the Web page frame with the specified name.

public:
 void Navigate(System::String ^ urlString, System::String ^ targetFrameName, cli::array <System::Byte> ^ postData, System::String ^ additionalHeaders);
public void Navigate (string urlString, string targetFrameName, byte[] postData, string additionalHeaders);
member this.Navigate : string * string * byte[] * string -> unit
Public Sub Navigate (urlString As String, targetFrameName As String, postData As Byte(), additionalHeaders As String)

參數

urlString
String

要載入之文件的 URL。The URL of the document to load.

targetFrameName
String

在其中載入文件的框架名稱。The name of the frame in which to load the document.

postData
Byte[]

HTTP POST 資料 (例如表單資料)。HTTP POST data such as form data.

additionalHeaders
String

要加入預設標頭的 HTTP 標頭。HTTP headers to add to the default headers.

例外狀況

這個 WebBrowser 執行個體已不再有效。This WebBrowser instance is no longer valid.

無法從基礎 ActiveX IWebBrowser2 控制項中擷取 WebBrowser 介面實作的參考。A reference to an implementation of the IWebBrowser2 interface could not be retrieved from the underlying ActiveX WebBrowser control.

備註

WebBrowser控制項會維護流覽會話期間所造訪之所有網頁的歷程記錄清單。The WebBrowser control maintains a history list of all the Web pages visited during a browsing session. 當您呼叫這個多載時,控制項會將位於 WebBrowser 指定 URI 的檔載入至具有指定之名稱的網頁框架,並將 URI 新增至歷程記錄清單的結尾。When you call this overload, the WebBrowser control loads the document at the specified URI into the Web page frame with the specified name, and adds the URI to the end of the history list. 如果指定的框架名稱無效,則會將檔載入至新的 Internet Explorer 視窗。If the frame name specified is invalid, the document is loaded into a new Internet Explorer window.

使用 GoBack 方法,將控制項傳回至導覽歷程記錄中的前一頁。Use the GoBack method to return the control to a previous page in the navigation history. 導覽後,請使用 GoForward 方法在流覽歷程記錄中返回較新的頁面。Use the GoForward method to return to a later page in the navigation history after navigating backward.

WebBrowser控制項會將最近造訪過的網站中的網頁儲存在本機硬碟上的快取中。The WebBrowser control stores Web pages from recently visited sites in a cache on the local hard disk. 每個頁面都可以指定到期日,指出它會保留在快取中的時間長度。Each page can specify an expiration date indicating how long it will remain in the cache. 當控制項流覽至頁面時,它會藉由顯示快取版本(如果有的話)來節省時間,而不是再次下載頁面。When the control navigates to a page, it saves time by displaying a cached version, if one is available, rather than downloading the page again. 使用 Refresh 方法 WebBrowser ,藉由下載來強制控制項重載目前的網頁,以確保控制項顯示最新版本。Use the Refresh method to force the WebBrowser control to reload the current page by downloading it, ensuring that the control displays the latest version.

另請參閱

適用於

Navigate(Uri, Boolean)

將指定的 Uri 所表示之位置處的文件載入至新瀏覽器視窗或 WebBrowser 控制項。Loads the document at the location indicated by the specified Uri into a new browser window or into the WebBrowser control.

public:
 void Navigate(Uri ^ url, bool newWindow);
public void Navigate (Uri url, bool newWindow);
member this.Navigate : Uri * bool -> unit
Public Sub Navigate (url As Uri, newWindow As Boolean)

參數

url
Uri

Uri,代表要載入之文件的 URL。A Uri representing the URL of the document to load.

newWindow
Boolean

true 會將文件載入至新瀏覽器視窗,false 則會將文件載入至 WebBrowser 控制項。true to load the document into a new browser window; false to load the document into the WebBrowser control.

例外狀況

這個 WebBrowser 執行個體已不再有效。This WebBrowser instance is no longer valid.

無法從基礎 ActiveX IWebBrowser2 控制項中擷取 WebBrowser 介面實作的參考。A reference to an implementation of the IWebBrowser2 interface could not be retrieved from the underlying ActiveX WebBrowser control.

url 參數值並非代表絕對 URI。The url parameter value does not represent an absolute URI. 如需詳細資訊,請參閱IsAbsoluteUriFor more information, see IsAbsoluteUri.

備註

WebBrowser控制項會維護流覽會話期間所造訪之所有網頁的歷程記錄清單。The WebBrowser control maintains a history list of all the Web pages visited during a browsing session. 當您呼叫具有參數值的這個多載時 newWindow false ,控制項會以一般方式流覽至指定的 URI,並將 URI 新增至歷程記錄清單的結尾。When you call this overload with a newWindow parameter value of false, the control navigates to the specified URI normally and adds the URI to the end of the history list. 當您呼叫具有參數值的這個多載時 newWindow trueWebBrowser 控制項會將位於指定 URI 的檔載入至新的 Internet Explorer 視窗,以維護自己的流覽歷程記錄。When you call this overload with a newWindow parameter value of true, the WebBrowser control loads the document at the specified URI into a new Internet Explorer window, which maintains its own navigation history. 您可以在 NewWindow 新的瀏覽器視窗開啟之前,處理事件以接收通知,讓您可以視需要取消動作。You can handle the NewWindow event to receive notification before a new browser window is opened, allowing you to cancel the action if necessary.

WebBrowser控制項會將最近造訪過的網站中的網頁儲存在本機硬碟上的快取中。The WebBrowser control stores Web pages from recently visited sites in a cache on the local hard disk. 每個頁面都可以指定到期日,指出它會保留在快取中的時間長度。Each page can specify an expiration date indicating how long it will remain in the cache. 當控制項流覽至頁面,或將頁面載入另一個瀏覽器視窗時,會顯示快取的版本(如果有的話),而不是再次下載頁面,藉此節省時間。When the control navigates to a page or loads a page into a separate browser window, it saves time by displaying a cached version, if one is available, rather than downloading the page again. 使用 Refresh 方法 WebBrowser ,藉由下載來強制控制項重載目前的網頁,以確保控制項顯示最新版本。Use the Refresh method to force the WebBrowser control to reload the current page by downloading it, ensuring that the control displays the latest version. 當頁面載入至不同的 Internet Explorer 視窗時,使用者可以按一下 [重新整理 ] 按鈕來 抓取最新版本。When a page is loaded into a separate Internet Explorer window, the user can retrieve the latest version by clicking the Refresh button.

另請參閱

適用於

Navigate(Uri, String)

將指定的 Uri 所表示之位置處的文件載入至 WebBrowser 控制項,會使用指定的名稱來取代網頁框架的內容。Loads the document at the location indicated by the specified Uri into the WebBrowser control, replacing the contents of the Web page frame with the specified name.

public:
 void Navigate(Uri ^ url, System::String ^ targetFrameName);
public void Navigate (Uri url, string targetFrameName);
member this.Navigate : Uri * string -> unit
Public Sub Navigate (url As Uri, targetFrameName As String)

參數

url
Uri

Uri,代表要載入之文件的 URL。A Uri representing the URL of the document to load.

targetFrameName
String

在其中載入文件的框架名稱。The name of the frame in which to load the document.

例外狀況

這個 WebBrowser 執行個體已不再有效。This WebBrowser instance is no longer valid.

無法從基礎 ActiveX IWebBrowser2 控制項中擷取 WebBrowser 介面實作的參考。A reference to an implementation of the IWebBrowser2 interface could not be retrieved from the underlying ActiveX WebBrowser control.

url 參數值並非代表絕對 URI。The url parameter value does not represent an absolute URI. 如需詳細資訊,請參閱IsAbsoluteUriFor more information, see IsAbsoluteUri.

備註

WebBrowser控制項會維護流覽會話期間所造訪之所有網頁的歷程記錄清單。The WebBrowser control maintains a history list of all the Web pages visited during a browsing session. 當您呼叫這個多載時,控制項會將位於 WebBrowser 指定 URI 的檔載入至具有指定之名稱的網頁框架,並將 URI 新增至歷程記錄清單的結尾。When you call this overload, the WebBrowser control loads the document at the specified URI into the Web page frame with the specified name, and adds the URI to the end of the history list. 如果指定的框架名稱無效,則會將檔載入至新的 Internet Explorer 視窗。If the frame name specified is invalid, the document is loaded into a new Internet Explorer window.

使用 GoBack 方法,將控制項傳回至導覽歷程記錄中的前一頁。Use the GoBack method to return the control to a previous page in the navigation history. 導覽後,請使用 GoForward 方法在流覽歷程記錄中返回較新的頁面。Use the GoForward method to return to a later page in the navigation history after navigating backward.

WebBrowser控制項會將最近造訪過的網站中的網頁儲存在本機硬碟上的快取中。The WebBrowser control stores Web pages from recently visited sites in a cache on the local hard disk. 每個頁面都可以指定到期日,指出它會保留在快取中的時間長度。Each page can specify an expiration date indicating how long it will remain in the cache. 當控制項流覽至頁面時,它會藉由顯示快取版本(如果有的話)來節省時間,而不是再次下載頁面。When the control navigates to a page, it saves time by displaying a cached version, if one is available, rather than downloading the page again. 使用 Refresh 方法 WebBrowser ,藉由下載來強制控制項重載目前的網頁,以確保控制項顯示最新版本。Use the Refresh method to force the WebBrowser control to reload the current page by downloading it, ensuring that the control displays the latest version.

另請參閱

適用於

Navigate(String, Boolean)

將指定的統一資源定位器 (URL) 處的文件載入至新瀏覽器視窗或 WebBrowser 控制項。Loads the document at the specified Uniform Resource Locator (URL) into a new browser window or into the WebBrowser control.

public:
 void Navigate(System::String ^ urlString, bool newWindow);
public void Navigate (string urlString, bool newWindow);
member this.Navigate : string * bool -> unit
Public Sub Navigate (urlString As String, newWindow As Boolean)

參數

urlString
String

要載入之文件的 URL。The URL of the document to load.

newWindow
Boolean

true 會將文件載入至新瀏覽器視窗,false 則會將文件載入至 WebBrowser 控制項。true to load the document into a new browser window; false to load the document into the WebBrowser control.

例外狀況

這個 WebBrowser 執行個體已不再有效。This WebBrowser instance is no longer valid.

無法從基礎 ActiveX IWebBrowser2 控制項中擷取 WebBrowser 介面實作的參考。A reference to an implementation of the IWebBrowser2 interface could not be retrieved from the underlying ActiveX WebBrowser control.

備註

WebBrowser控制項會維護流覽會話期間所造訪之所有網頁的歷程記錄清單。The WebBrowser control maintains a history list of all the Web pages visited during a browsing session. 當您呼叫具有參數值的這個多載時 newWindow false ,控制項會以一般方式流覽至指定的 URI,並將 URI 新增至歷程記錄清單的結尾。When you call this overload with a newWindow parameter value of false, the control navigates to the specified URI normally and adds the URI to the end of the history list. 當您呼叫具有參數值的這個多載時 newWindow trueWebBrowser 控制項會將位於指定 URI 的檔載入至新的 Internet Explorer 視窗,以維護自己的流覽歷程記錄。When you call this overload with a newWindow parameter value of true, the WebBrowser control loads the document at the specified URI into a new Internet Explorer window, which maintains its own navigation history. 您可以在 NewWindow 新的瀏覽器視窗開啟之前,處理事件以接收通知,讓您可以視需要取消動作。You can handle the NewWindow event to receive notification before a new browser window is opened, allowing you to cancel the action if necessary.

WebBrowser控制項會將最近造訪過的網站中的網頁儲存在本機硬碟上的快取中。The WebBrowser control stores Web pages from recently visited sites in a cache on the local hard disk. 每個頁面都可以指定到期日,指出它會保留在快取中的時間長度。Each page can specify an expiration date indicating how long it will remain in the cache. 當控制項流覽至頁面,或將頁面載入另一個瀏覽器視窗時,會顯示快取的版本(如果有的話),而不是再次下載頁面,藉此節省時間。When the control navigates to a page or loads a page into a separate browser window, it saves time by displaying a cached version, if one is available, rather than downloading the page again. 使用 Refresh 方法 WebBrowser ,藉由下載來強制控制項重載目前的網頁,以確保控制項顯示最新版本。Use the Refresh method to force the WebBrowser control to reload the current page by downloading it, ensuring that the control displays the latest version. 當頁面載入至不同的 Internet Explorer 視窗時,使用者可以按一下 [重新整理 ] 按鈕來 抓取最新版本。When a page is loaded into a separate Internet Explorer window, the user can retrieve the latest version by clicking the Refresh button.

另請參閱

適用於

Navigate(String, String)

將指定之統一資源定位器 (URL) 處的文件載入至 WebBrowser 控制項,會使用指定的名稱來取代網頁框架的內容。Loads the document at the specified Uniform Resource Locator (URL) into the WebBrowser control, replacing the contents of the Web page frame with the specified name.

public:
 void Navigate(System::String ^ urlString, System::String ^ targetFrameName);
public void Navigate (string urlString, string targetFrameName);
member this.Navigate : string * string -> unit
Public Sub Navigate (urlString As String, targetFrameName As String)

參數

urlString
String

要載入之文件的 URL。The URL of the document to load.

targetFrameName
String

在其中載入文件的框架名稱。The name of the frame in which to load the document.

例外狀況

這個 WebBrowser 執行個體已不再有效。This WebBrowser instance is no longer valid.

無法從基礎 ActiveX IWebBrowser2 控制項中擷取 WebBrowser 介面實作的參考。A reference to an implementation of the IWebBrowser2 interface could not be retrieved from the underlying ActiveX WebBrowser control.

備註

WebBrowser控制項會維護流覽會話期間所造訪之所有網頁的歷程記錄清單。The WebBrowser control maintains a history list of all the Web pages visited during a browsing session. 當您呼叫這個多載時,控制項會將位於 WebBrowser 指定 URI 的檔載入至具有指定之名稱的網頁框架,並將 URI 新增至歷程記錄清單的結尾。When you call this overload, the WebBrowser control loads the document at the specified URI into the Web page frame with the specified name, and adds the URI to the end of the history list. 如果指定的框架名稱無效,則會將檔載入至新的 Internet Explorer 視窗。If the frame name specified is invalid, the document is loaded into a new Internet Explorer window.

使用 GoBack 方法,將控制項傳回至導覽歷程記錄中的前一頁。Use the GoBack method to return the control to a previous page in the navigation history. 導覽後,請使用 GoForward 方法在流覽歷程記錄中返回較新的頁面。Use the GoForward method to return to a later page in the navigation history after navigating backward.

WebBrowser控制項會將最近造訪過的網站中的網頁儲存在本機硬碟上的快取中。The WebBrowser control stores Web pages from recently visited sites in a cache on the local hard disk. 每個頁面都可以指定到期日,指出它會保留在快取中的時間長度。Each page can specify an expiration date indicating how long it will remain in the cache. 當控制項流覽至頁面時,它會藉由顯示快取版本(如果有的話)來節省時間,而不是再次下載頁面。When the control navigates to a page, it saves time by displaying a cached version, if one is available, rather than downloading the page again. 使用 Refresh 方法 WebBrowser ,藉由下載來強制控制項重載目前的網頁,以確保控制項顯示最新版本。Use the Refresh method to force the WebBrowser control to reload the current page by downloading it, ensuring that the control displays the latest version.

另請參閱

適用於

Navigate(Uri)

將指定的 Uri 所表示之位置處的文件載入至 WebBrowser 控制項,會取代前一份文件。Loads the document at the location indicated by the specified Uri into the WebBrowser control, replacing the previous document.

public:
 void Navigate(Uri ^ url);
public void Navigate (Uri url);
member this.Navigate : Uri -> unit
Public Sub Navigate (url As Uri)

參數

url
Uri

Uri,代表要載入之文件的 URL。A Uri representing the URL of the document to load.

例外狀況

這個 WebBrowser 執行個體已不再有效。This WebBrowser instance is no longer valid.

無法從基礎 ActiveX IWebBrowser2 控制項中擷取 WebBrowser 介面實作的參考。A reference to an implementation of the IWebBrowser2 interface could not be retrieved from the underlying ActiveX WebBrowser control.

url 參數值並非代表絕對 URI。The url parameter value does not represent an absolute URI. 如需詳細資訊,請參閱IsAbsoluteUriFor more information, see IsAbsoluteUri.

範例

下列程式碼範例示範如何使用 Navigate 方法來執行控制項的網址列 WebBrowserThe following code example demonstrates how to use the Navigate method to implement an address bar for the WebBrowser control. 此範例會要求您的表單包含名為的 WebBrowser 控制項 webBrowser1 、名為的 TextBox 控制項 TextBoxAddress ,以及名為的 Button 控制項 ButtonGoThis example requires that your form contains a WebBrowser control called webBrowser1, a TextBox control called TextBoxAddress, and a Button control called ButtonGo. 當您在文字方塊中輸入 URL,然後按 enter 鍵或按一下 [執行 ] 按鈕時, WebBrowser 控制項會流覽至指定的 url。When you type a URL into the text box and press ENTER or click the Go button, the WebBrowser control navigates to the URL specified. 當您按一下超連結流覽時,文字方塊會自動更新以顯示目前的 URL。When you navigate by clicking a hyperlink, the text box automatically updates to display the current URL.

如需完整的程式碼範例,請參閱 如何:將 Web 瀏覽器功能加入至 Windows Forms 應用程式For the complete code example, see How to: Add Web Browser Capabilities to a Windows Forms Application.

// Navigates to the URL in the address text box when 
// the ENTER key is pressed while the text box has focus.
void TextBoxAddress_KeyDown( Object^ /*sender*/, System::Windows::Forms::KeyEventArgs^ e )
{
   if ( e->KeyCode == System::Windows::Forms::Keys::Enter &&  !this->TextBoxAddress->Text->Equals( "" ) )
   {
      this->WebBrowser1->Navigate( this->TextBoxAddress->Text );
   }
}

// Navigates to the URL in the address text box when 
// the Go button is clicked.
void ButtonGo_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   if (  !this->TextBoxAddress->Text->Equals( "" ) )
   {
      this->WebBrowser1->Navigate( this->TextBoxAddress->Text );
   }
}

// Updates the URL in TextBoxAddress upon navigation.
void WebBrowser1_Navigated( Object^ /*sender*/, System::Windows::Forms::WebBrowserNavigatedEventArgs^ /*e*/ )
{
   this->TextBoxAddress->Text = this->WebBrowser1->Url->ToString();
}

// Navigates to the URL in the address box when 
// the ENTER key is pressed while the ToolStripTextBox has focus.
private void toolStripTextBox1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        Navigate(toolStripTextBox1.Text);
    }
}

// Navigates to the URL in the address box when 
// the Go button is clicked.
private void goButton_Click(object sender, EventArgs e)
{
    Navigate(toolStripTextBox1.Text);
}

// Navigates to the given URL if it is valid.
private void Navigate(String address)
{
    if (String.IsNullOrEmpty(address)) return;
    if (address.Equals("about:blank")) return;
    if (!address.StartsWith("http://") &&
        !address.StartsWith("https://"))
    {
        address = "http://" + address;
    }
    try
    {
        webBrowser1.Navigate(new Uri(address));
    }
    catch (System.UriFormatException)
    {
        return;
    }
}

// Updates the URL in TextBoxAddress upon navigation.
private void webBrowser1_Navigated(object sender,
    WebBrowserNavigatedEventArgs e)
{
    toolStripTextBox1.Text = webBrowser1.Url.ToString();
}

' 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

備註

WebBrowser控制項會維護流覽會話期間所造訪之所有網頁的歷程記錄清單。The WebBrowser control maintains a history list of all the Web pages visited during a browsing session. 當您呼叫這個多載時, WebBrowser 控制項會流覽至指定的 URI,並將它新增至歷程記錄清單的結尾。When you call this overload, the WebBrowser control navigates to the specified URI and adds it to the end of the history list. 使用 GoBack 方法,將控制項傳回至導覽歷程記錄中的前一頁。Use the GoBack method to return the control to a previous page in the navigation history. 導覽後,請使用 GoForward 方法在流覽歷程記錄中返回較新的頁面。Use the GoForward method to return to a later page in the navigation history after navigating backward.

WebBrowser控制項會將最近造訪過的網站中的網頁儲存在本機硬碟上的快取中。The WebBrowser control stores Web pages from recently visited sites in a cache on the local hard disk. 每個頁面都可以指定到期日,指出它會保留在快取中的時間長度。Each page can specify an expiration date indicating how long it will remain in the cache. 當控制項流覽至頁面時,它會藉由顯示快取版本(如果有的話)來節省時間,而不是再次下載頁面。When the control navigates to a page, it saves time by displaying a cached version, if one is available, rather than downloading the page again. 使用 Refresh 方法 WebBrowser ,藉由下載來強制控制項重載目前的網頁,以確保控制項顯示最新版本。Use the Refresh method to force the WebBrowser control to reload the current page by downloading it, ensuring that the control displays the latest version.

您可以使用 Navigate 方法來執行類似 Internet Explorer 中的網址列。You can use the Navigate method to implement an address bar similar to the one in Internet Explorer.

另請參閱

適用於

Navigate(String)

將指定之統一資源定位器 (URL) 處的文件載入至 WebBrowser 控制項,會取代前一份文件。Loads the document at the specified Uniform Resource Locator (URL) into the WebBrowser control, replacing the previous document.

public:
 void Navigate(System::String ^ urlString);
public void Navigate (string urlString);
member this.Navigate : string -> unit
Public Sub Navigate (urlString As String)

參數

urlString
String

要載入之文件的 URL。The URL of the document to load.

例外狀況

這個 WebBrowser 執行個體已不再有效。This WebBrowser instance is no longer valid.

無法從基礎 ActiveX IWebBrowser2 控制項中擷取 WebBrowser 介面實作的參考。A reference to an implementation of the IWebBrowser2 interface could not be retrieved from the underlying ActiveX WebBrowser control.

備註

WebBrowser控制項會維護流覽會話期間所造訪之所有網頁的歷程記錄清單。The WebBrowser control maintains a history list of all the Web pages visited during a browsing session. 當您呼叫這個多載時, WebBrowser 控制項會流覽至指定的 URI,並將它新增至歷程記錄清單的結尾。When you call this overload, the WebBrowser control navigates to the specified URI and adds it to the end of the history list. 使用 GoBack 方法,將控制項傳回至導覽歷程記錄中的前一頁。Use the GoBack method to return the control to a previous page in the navigation history. 導覽後,請使用 GoForward 方法在流覽歷程記錄中返回較新的頁面。Use the GoForward method to return to a later page in the navigation history after navigating backward.

WebBrowser控制項會將最近造訪過的網站中的網頁儲存在本機硬碟上的快取中。The WebBrowser control stores Web pages from recently visited sites in a cache on the local hard disk. 每個頁面都可以指定到期日,指出它會保留在快取中的時間長度。Each page can specify an expiration date indicating how long it will remain in the cache. 當控制項流覽至頁面時,它會藉由顯示快取版本(如果有的話)來節省時間,而不是再次下載頁面。When the control navigates to a page, it saves time by displaying a cached version, if one is available, rather than downloading the page again. 使用 Refresh 方法 WebBrowser ,藉由下載來強制控制項重載目前的網頁,以確保控制項顯示最新版本。Use the Refresh method to force the WebBrowser control to reload the current page by downloading it, ensuring that the control displays the latest version.

您可以使用 Navigate 方法來執行類似 Internet Explorer 中的網址列。You can use the Navigate method to implement an address bar similar to the one in Internet Explorer.

另請參閱

適用於