Compartir a través de


Cómo: Cambiar las características de las ventanas

Las ventanas de Visual Studio las representa el objeto Window2 en el modelo de automatización. Las características físicas de una ventana se pueden manipular mediante el uso de sus miembros, por ejemplo, alto, ancho, visibilidad, etc. Mediante la colección Window2, se puede crear una ventana vinculada, que esté formada por dos o más ventanas de herramientas acopladas. Los miembros permiten también acoplar ventanas adicionales al marco o desacoplarlas de éste.

Nota

Se deben ver las ventanas que se van a vincular. Si alguna de las ventanas está oculta, se obtiene una excepción. Puede mostrar ventanas mediante la propiedad Visible.

La colección Windows2 permite, asimismo, crear ventanas de herramientas propias. Para obtener más información, vea Cómo: Crear y controlar ventanas de herramientas.

Nota

Los cuadros de diálogo y comandos de menú que se ven pueden diferir de los descritos en la Ayuda, en función de los valores de configuración o de edición activos. Estos procedimientos se han desarrollado con la Configuración de desarrollo general activa. Para cambiar la configuración, elija la opción Importar y exportar configuraciones del menú Herramientas. Para obtener más información, vea Trabajar con valores de configuración.

Ejemplo

Los siguientes ejemplos muestran cómo hacer referencia y utilizar los diversos miembros del modelo de automatización para manipular las ventanas de herramientas. En ellos se crea una ventana de herramientas vinculada y se insertan dos ventanas de herramientas de Visual Studio, que son la ventana Explorador de soluciones y la Ventana de salida, que se vinculan. También se muestra la forma de cambiar el tamaño de las ventanas de herramientas y cómo desacoplarlas. Antes de ejecutar este código, asegúrese de que la propiedad "Embed Interop Types" de la referencia del ensamblado EnvDTE está establecida en false. Para obtener más información acerca de cómo se ejecuta el código de ejemplo en un complemento, vea Cómo: Compilar y ejecutar los ejemplos de código del modelo de objetos de automatización.

Nota de precauciónPrecaución

Al ejecutar este ejemplo, se cambiará el diseño actual de las ventanas de herramientas de Visual Studio.

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)
    chgWindow(_applicationObject)
End Sub

Public Sub chgWindow(ByVal dte As DTE2)
    ' Create variables for the various tool windows.
    Dim winFrame As EnvDTE80.Window2
    Dim win1 As Window = _
      dte.Windows.Item(Constants.vsWindowKindSolutionExplorer)
    Dim win2 As Window = dte.Windows. _
    Item(Constants.vsWindowKindOutput)
    Dim win3 As Window = dte.Windows. _
    Item(Constants.vsWindowKindCommandWindow)

    ' Create a linked window frame and dock Solution 
    ' Explorer and the Ouput window together inside it.
    winFrame = CType(dte.Windows.CreateLinkedWindowFrame(win1, win2, _
      vsLinkedWindowType.vsLinkedWindowTypeDocked), Window2)
    MsgBox("Total number of windows in the linked window frame: " & _
    winFrame.LinkedWindows.Count)

    ' Add another tool window, the Command window, to the frame 
    ' with the other two.
    winFrame.LinkedWindows.Add(win3)
    MsgBox("Total number of windows in the linked window frame: " & _
    winFrame.LinkedWindows.Count)

    ' Resize the entire linked window frame.
    winFrame.Width = 500
    winFrame.Height = 600
    MsgBox("Frame height and width changed. Now changing Command _
      window height.")

    ' Resize the height of the Command window.
    winFrame.LinkedWindows.Item(3).Height = 800
    MsgBox("Now undocking the Command window from the frame.")

    ' Undock the Command window from the frame.
    winFrame.LinkedWindows.Remove(win3)
End Sub
public void OnConnection(object application, ext_ConnectMode 
  connectMode, object addInInst, ref Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    chgWindow(_applicationObject);
}

public void chgWindow(DTE2 dte)
{
    // Create variables for the various tool windows.
    EnvDTE80.Window2 winFrame;
    Window win1 = 
      dte.Windows.Item(Constants.vsWindowKindSolutionExplorer);
    Window win2 = dte.Windows.Item(Constants.vsWindowKindOutput);
    Window win3 = 
      dte.Windows.Item(Constants.vsWindowKindCommandWindow);

    // Create a linked window frame and dock Solution 
    // Explorer and the Ouput window together inside it.
    winFrame = (Window2)dte.Windows.CreateLinkedWindowFrame(win1, win2, 
      vsLinkedWindowType.vsLinkedWindowTypeDocked);
    System.Windows.Forms.MessageBox.Show("Total number of windows in 
      the linked window frame: " + winFrame.LinkedWindows.Count);

    // Add another tool window, the Command window, to the frame 
    // with the other two.
    winFrame.LinkedWindows.Add(win3);
    System.Windows.Forms.MessageBox.Show(
      "Total number of windows in the linked window frame: " + 
      winFrame.LinkedWindows.Count);

    // Resize the entire linked window frame.
    winFrame.Width = 500;
    winFrame.Height = 600;
    System.Windows.Forms.MessageBox.Show(
      "Frame height and width changed." +
      "Now changing Command window height.");

    // Resize the height of the Command window.
    winFrame.LinkedWindows.Item(3).Height = 800;
    System.Windows.Forms.MessageBox.Show(
      "Now undocking the Command window from the frame.");

    // Undock the Command window from the frame.
    winFrame.LinkedWindows.Remove(win3);
}

Vea también

Tareas

Cómo: Crear y controlar ventanas de herramientas

Cómo: Crear un complemento

Tutorial: Crear un asistente

Conceptos

Gráfico del modelo de objetos de automatización

Otros recursos

Crear y controlar las ventanas del entorno

Crear complementos y asistentes

Referencia de automatización y extensibilidad