WebBrowser.DocumentTitle 屬性

定義

取得目前在 WebBrowser 控制項中顯示之文件的標題。

public:
 property System::String ^ DocumentTitle { System::String ^ get(); };
[System.ComponentModel.Browsable(false)]
public string DocumentTitle { get; }
[<System.ComponentModel.Browsable(false)>]
member this.DocumentTitle : string
Public ReadOnly Property DocumentTitle As String

屬性值

目前文件的標題;如果未載入任何文件,則為空字串 ("")。

屬性

例外狀況

這個 WebBrowser 執行個體已不再有效。

無法從基礎 ActiveX IWebBrowser2 控制項中擷取 WebBrowser 介面實作的參考。

範例

下列程式碼範例示範如何使用 DocumentTitle 屬性,以目前檔的標題更新表單標題列。 此範例會要求表單包含 WebBrowser 名為 的 webBrowser1 控制項。

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

// Updates the title bar with the current document title.
void WebBrowser1_DocumentTitleChanged( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   this->Text = WebBrowser1->DocumentTitle;
}
// Updates the title bar with the current document title.
private void webBrowser1_DocumentTitleChanged(object sender, EventArgs e)
{
    this.Text = webBrowser1.DocumentTitle;
}
' Updates the title bar with the current document title.
Private Sub webBrowser1_DocumentTitleChanged( _
    ByVal sender As Object, ByVal e As EventArgs) _
    Handles webBrowser1.DocumentTitleChanged

    Me.Text = webBrowser1.DocumentTitle

End Sub

備註

例如,當您想要在應用程式的標題列中顯示檔標題時,這個屬性很有用。 如果目前檔沒有定義標題,這個屬性會設定為檔位置和檔案名。

DocumentTitleChanged處理事件,以在控制項巡覽至新檔時,更新標題列中 WebBrowser 的標題。

適用於

另請參閱