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 窗体应用程序添加 Web 浏览器功能

// 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 更新标题栏中的标题。

适用于

另请参阅