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

适用于

产品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

另请参阅