共用方式為


CommandWindow.TextDocument 屬性

取得視窗或窗格的 TextDocument

命名空間:  EnvDTE
組件:  EnvDTE (在 EnvDTE.dll 中)

語法

'宣告
ReadOnly Property TextDocument As TextDocument
    Get
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 命名空間

其他資源

HOW TO:編譯和執行 Automation 物件模型程式碼範例