WebBrowser.GoForward 方法

定義

WebBrowser 控制項巡覽至巡覽記錄中的下一頁 (如果有的話)。

public:
 bool GoForward();
public bool GoForward ();
member this.GoForward : unit -> bool
Public Function GoForward () As Boolean

傳回

如果巡覽成功,則為 true,如果無法取得巡覽記錄中的下一頁,則為 false

範例

下列程式碼範例示範如何使用 GoForward 方法來實 WebBrowser 作類似 Internet Explorer 中控制項的[轉寄] 按鈕。 此範例會要求您的表單包含 WebBrowser 名為 的 webBrowser1 控制項,以及 Button 名為 的 ButtonForward 控制項。

如需完整的程式碼範例,請參閱如何:將網頁瀏覽器功能新增至Windows Forms應用程式

// Navigates WebBrowser1 to the next page in history.
void ButtonForward_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   this->WebBrowser1->GoForward();
}

// Disables the Forward button at the end of navigation history.
void WebBrowser1_CanGoForwardChanged( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   this->ButtonForward->Enabled = this->WebBrowser1->CanGoForward;
}
// Navigates webBrowser1 to the next page in history.
private void forwardButton_Click(object sender, EventArgs e)
{
    webBrowser1.GoForward();
}

// Disables the Forward button at the end of navigation history.
private void webBrowser1_CanGoForwardChanged(object sender, EventArgs e)
{
    forwardButton.Enabled = webBrowser1.CanGoForward;
}
' Navigates webBrowser1 to the next page in history.
Private Sub forwardButton_Click( _
    ByVal sender As Object, ByVal e As EventArgs) _
    Handles forwardButton.Click

    webBrowser1.GoForward()

End Sub

' Disables the Forward button at the end of navigation history.
Private Sub webBrowser1_CanGoForwardChanged( _
    ByVal sender As Object, ByVal e As EventArgs) _
    Handles webBrowser1.CanGoForwardChanged

    forwardButton.Enabled = webBrowser1.CanGoForward

End Sub

備註

控制項 WebBrowser 會維護流覽會話期間所流覽之所有網頁的歷程記錄清單。 您可以使用 GoForward 方法來實作類似 Internet Explorer 中的 [轉寄 ] 按鈕,讓使用者在向後流覽後返回流覽歷程記錄中的下一頁。

CanGoForward使用 屬性來判斷導覽歷程記錄是否可用,並且包含位於目前頁面之後的頁面。 處理 事件, CanGoForwardChanged 以在屬性值變更時 CanGoForward 接收通知。 例如,當控制項巡覽至或離開流覽歷程記錄的結尾時 WebBrowser ,處理此事件很有用。若要變更 [轉寄] 按鈕的啟用狀態。

適用於

另請參閱