How to: Control the Output Window

The Output window displays status messages for various features in the integrated development environment (IDE). These include build errors that occur when a project is compiled, and the results when Transact-SQL syntax in a stored procedure is checked against a target database. Certain IDE features, for example, the external tools features or commands that are invoked in the Command window, deliver output to special Output window panes. Output from external tools, for example, .bat files or .com files, which is typically displayed in the Windows Command Prompt window, can also be displayed in the Output window.

The Visual Studio automation model offers the following objects that you can use to control the Output window.

Object Name

Description

OutputWindow

Represents the Output window.

OutputWindowPanes

A collection that contains all the Output window panes.

OutputWindowPane

Represents just one pane in the Output window.

OutputWindowEvents

Lets you respond to events that occur in the Output window.

In addition to controlling the contents of the Output window, you can also control characteristics such as its width and height. For more information, see How to: Change Window Characteristics.

The text inside the Output window panes can be manipulated by using the Visual Studio editor automation model, just as code in the Code editor can be manipulated, by using the TextDocument object, EditPoint object, or similar objects. For more information, see How to: Control the Code Editor (Visual Basic).

NoteNote

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. These procedures were developed with the General Development Settings active. To change your settings, click Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

This example demonstrates how to add a new window pane to the Output window and how to add some text to it. For more information about how to run the example, see How to: Compile and Run the Automation Object Model Code Examples.

public void OnConnection(object application, ext_ConnectMode 
  connectMode, object addInInst, ref Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    // Pass the applicationObject member variable to the code example.
    OutputWindowTest(_applicationObject);
}

public void OutputWindowTest(DTE2 dte)
{
    // Create a tool window reference for the Output window
    // and window pane.
    OutputWindow ow = dte.ToolWindows.OutputWindow;
    OutputWindowPane owP;

    // Add a new pane to the Output window.
    owP = ow.OutputWindowPanes.Add("A New Pane");
    // Add a line of text to the new pane.
    owP.OutputString("Some Text");
}

This example adds text to the Build pane in the Output window and then retrieves it.

using System.Windows.Forms;
public void OnConnection(object application, ext_ConnectMode 
  connectMode, object addInInst, ref Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    // Pass the applicationObject member variable to the code example.
    writeReadOW(_applicationObject);
}

public void writeReadOW(DTE2 dte)
{
    // Add-in code.
    // Create a reference to the Output window.
    // Create a tool window reference for the Output window
    // and window pane.
    OutputWindow ow = dte.ToolWindows.OutputWindow;
    OutputWindowPane owP;
    // Create a reference to the pane contents.
    TextDocument owPTxtDoc;
    EditPoint2 strtPt;

    // Select the Build pane in the Output window.
    owP = ow.OutputWindowPanes.Item("Build");
    owP.Activate();
    owPTxtDoc = owP.TextDocument;
            
    // Put some text in the pane.
    owP.OutputString("Testing 123.");
    // Retrieve the text contents of the pane.
    System.Windows.Forms.MessageBox.Show("Startpoint: " + 
      owPTxtDoc.StartPoint.DisplayColumn);
    strtPt = (EditPoint2)owPTxtDoc.StartPoint.CreateEditPoint();
    System.Windows.Forms.MessageBox.Show
      (strtPt.GetText(owPTxtDoc.EndPoint));
}
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2015 Microsoft