WebBrowser.DocumentTitle 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得目前在 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 的標題。
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應