_DTE.ActiveDocument 属性

获取活动文档。

命名空间:  EnvDTE
程序集:  EnvDTE(在 EnvDTE.dll 中)

语法

声明
ReadOnly Property ActiveDocument As Document
    Get
Document ActiveDocument { get; }
property Document^ ActiveDocument {
    Document^ get ();
}
abstract ActiveDocument : Document
function get ActiveDocument () : Document

属性值

类型:EnvDTE.Document
一个 Document 对象。

备注

活动文档是具有焦点的文档。 若要使另一个文档变成活动文档,请在其窗口上设置焦点。

只可对“工具”窗口设置标题。 如果尝试对其他窗口类型(如“文档”窗口)设置标题,则会遇到错误“未指定的错误”。

示例

Sub ActiveDocumentExample()
  Dim objTextDoc As TextDocument
  Dim objEP As EditPoint
  
  'Create a new text document.
  Call DTE.ItemOperations.NewFile("General\Text File")
  'Get a handle to the new document.
  Set objTextDoc = DTE.ActiveDocument.Object("TextDocument")
  Set objEP = objTextDoc.StartPoint.CreateEditPoint
  'Create an EditPoint and add some text.
  objEP.Insert "A test sentence."
End Sub

Sub DocumentExample()
  Dim doc As Document
  Dim desc As String

  Set doc = DTE.ActiveDocument
  desc = "You are editing a "
  If (doc.ReadOnly) Then
    desc = desc & "read-only"
  Else
    desc = desc & "writable"
  End If
  desc = desc & " document called " & doc.Name & " located at " & doc.Path
  MsgBox desc
End Sub

.NET Framework 安全性

请参见

参考

_DTE 接口

EnvDTE 命名空间