CommandWindow.TextDocument 属性

获取窗口或窗格的 TextDocument

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

语法

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

属性值

类型:EnvDTE.TextDocument
TextDocument 对象。

备注

尝试通过此属性或 EditPoint 对象修改文档将失败,原因是整个文档的区域都是只读的。您只能通过 CommandWindow 对象中的成员修改文档。

示例

public void CodeExample(DTE2 dte, AddIn addin)
{
    try
    {
        // Get a reference to a Command window.
        Window win = dte.Windows.Item(EnvDTE.Constants.vsWindowKindCommandWindow);
        CommandWindow cmdWin = (CommandWindow)win.Object;
        // Add some text to the window.
        cmdWin.OutputString("This is a line of text in the CommandWindow TextDocument");
        // Return the contents of the TextDocument and display them.
        TextDocument txtDoc = cmdWin.TextDocument;
        TextSelection txtSel = txtDoc.Selection;
        TextRanges txtRanges = txtSel.TextRanges;
        // Show text in textdocument.
        foreach (TextRange txtRange in txtRanges)
        {
            txtRange.StartPoint.StartOfDocument();
            MessageBox.Show(txtRange.StartPoint.GetText(txtRange.EndPoint));
        }
        // Show the CommandWindow's parent object's caption property.
        MessageBox.Show("The Parent window's caption: " + cmdWin.Parent.Caption);
        // Show the application object containing the CommandWindow.
        MessageBox.Show(cmdWin.DTE.Name);
    }
    catch(Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

.NET Framework 安全性

请参见

参考

CommandWindow 接口

EnvDTE 命名空间

其他资源

如何:编译和运行自动化对象模型代码示例