WebBrowser.CanGoForward 屬性

定義

取得值,表示是否可使用巡覽記錄中的下一頁,這能讓 GoForward() 方法順利完成。

public:
 property bool CanGoForward { bool get(); };
[System.ComponentModel.Browsable(false)]
public bool CanGoForward { get; }
[<System.ComponentModel.Browsable(false)>]
member this.CanGoForward : bool
Public ReadOnly Property CanGoForward As Boolean

屬性值

如果控制項可向前巡覽,則為 true;否則為 false

屬性

範例

下列程式碼範例示範如何使用 事件的處理常式 CanGoForward ,實 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 會將 WebBrowser 控制項巡覽至此歷程記錄中的下一頁。 如果這個屬性是 true ,方法 GoForward 將會成功。 否則,呼叫 GoForward 方法會傳回 的值 false ,而且不會發生任何導覽。

CanGoForward使用 屬性來判斷導覽歷程記錄是否可用,並包含位於目前頁面之後的頁面,讓 GoForward 方法能夠成功。

您也可以處理 事件, CanGoForwardChanged 以在屬性變更時 CanGoForward 接收通知。 例如,當控制項巡覽至或離開流覽歷程記錄的結尾時 WebBrowser ,處理此事件很有用。若要變更 [轉寄] 按鈕的啟用狀態。

適用於

另請參閱