Freigeben über


Gewusst wie: Steuern des Befehlsfensters

Aktualisiert: November 2007

The CommandWindow object represents the Command window in the Visual Studio automation model. You can use the CommandWindow object to:

  • Insert a command into the Command window and, optionally, execute it by using the SendInput method.

  • Insert informational text into the Command window by using the OutputString method.

  • Clear all text from the Command window by using the Clear method.

In addition to controlling the contents of the Command window, you can also control its characteristics, such as width and height. For more information, see Gewusst wie: Ändern des Erscheinungsbilds eines Fensters.

Hinweis:

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 ExportSettings on the Tools menu. For more information, see Visual Studio-Einstellungen.

Beispiel

This example demonstrates how to reference and use the various members of the Command window automation model. For more information about how to run the example, see Gewusst wie: Kompilieren und Ausführen der Codebeispiele für das Automatisierungsobjektmodell.

Public Sub OnConnection(ByVal application As Object, ByVal _
  connectMode As ext_ConnectMode, ByVal addInInst As Object, _
  ByRef custom As Array) Implements IDTExtensibility2.OnConnection
    _applicationObject = CType(application, DTE2)
    _addInInstance = CType(addInInst, AddIn)
    ' Pass the applicationObject member variable to the code example.
    CommandWinExample(_applicationObject)
End Sub

Sub CommandWinExample(ByVal dte As DTE2)
    Try
        ' Get a reference to the Command window.
        Dim CW As CommandWindow = dte.ToolWindows.CommandWindow

        ' Insert informative text into the Command window.
        CW.OutputString("This takes you to the Microsoft Web site.")

        ' Add a command to the Command window and execute it.
        CW.SendInput("nav https://www.microsoft.com", True)

        ' Clear the contents of the Command window.
        MsgBox("Clearing the Command window...")
        CW.Clear()
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub
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.
    CommandWinExample(_applicationObject);
}

public void CommandWinExample(DTE2 dte)
{
    try
    {
        // Get a reference to the Command window.
        CommandWindow CW = dte.ToolWindows.CommandWindow;

        // Insert informative text into the Command window.
        CW.OutputString("This takes you to the Microsoft Web site.");

        // Add a command to the Command window and execute it.
        CW.SendInput("nav https://www.microsoft.com", true);

        // Clear the contents of the Command window.
        System.Windows.Forms.MessageBox.Show("Clearing the Command 
          window...");
        CW.Clear();
    }
    catch (Exception ex)
    {
        System.Windows.Forms.MessageBox.Show(ex.Message);
    }
}

Siehe auch

Aufgaben

Gewusst wie: Ändern des Erscheinungsbilds eines Fensters

Gewusst wie: Erstellen von Add-Ins

Exemplarische Vorgehensweise: Erstellen eines Assistenten

Konzepte

Diagramm "Automationsobjektmodell"

Weitere Ressourcen

Erstellen und Steuern von Umgebungsfenstern

Erstellen von Add-Ins und Assistenten

Referenz zur Automatisierung und Erweiterbarkeit