Share via


Procedura: controllare la finestra di comando

L'oggetto CommandWindow rappresenta la finestra di comando nel modello di automazione di Visual Studio.È possibile utilizzare l'oggetto CommandWindow per:

  • Inserire un comando nella finestra di comando e facoltativamente eseguirlo utilizzando il metodo SendInput.

  • Inserire del testo informativo nella finestra di comando utilizzando il metodo OutputString.

  • Eliminare interamente il testo presente nella finestra di comando utilizzando il metodo Clear.

Oltre a controllare il contenuto della finestra di comando, è possibile controllarne caratteristiche quali larghezza e altezza.Per ulteriori informazioni, vedere Procedura: modificare le caratteristiche delle finestre.

[!NOTA]

È possibile che le finestre di dialogo e i comandi di menu visualizzati siano diversi da quelli descritti nella Guida a seconda delle impostazioni attive o dell'edizione del programma.Queste procedure sono state sviluppate con le Impostazioni generali per lo sviluppo attive.Per modificare le impostazioni, scegliere Importa/EsportaImpostazioni dal menu Strumenti.Per ulteriori informazioni, vedere Impostazioni di Visual Studio.

Esempio

Nell'esempio viene illustrato come fare riferimento ai diversi membri del modello di automazione della finestra di comando e come utilizzarli.Per ulteriori informazioni su come eseguire l'esempio, vedere Procedura: compilare ed eseguire gli esempi di codice del modello a oggetti di automazione.

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);
    }
}

Vedere anche

Attività

Procedura: modificare le caratteristiche delle finestre

Procedura: creare un componente aggiuntivo

Procedura dettagliata: creazione di una procedura guidata

Concetti

Grafico del modello a oggetti di automazione

Altre risorse

Creazione e controllo delle finestre di ambiente

Creazione di componenti aggiuntivi e di procedure guidate

Riferimenti su Extensibility e automazione