Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

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, such as the external tools features or commands invoked in the Command window, deliver output to special Output Window panes. Output from external tools, such as .bat or .com files, normally displayed in the Windows Command window, can display in this window as well.

The Visual Studio automation model offers the following objects for controlling the Output window:

Object Name

Description

OutputWindow

Represents the Output window.

OutputWindowPanes

A collection containing all of the Output window panes.

OutputWindowPane

Represents a single pane in the Output window.

OutputWindowEvents

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

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

The text inside the Output window panes can be manipulated with the Visual Studio editor automation model, just like code in the Code editor, by using the TextDocument object, EditPoint object, and 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, choose 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));
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.