Compartir a través de


Cómo: Abra una ventana de herramientas mediante programación

Las ventanas de herramientas están abiertas normalmente haciendo clic en un comando de un menú, o presionando un método abreviado de teclado equivalente. Sin embargo, puede que tenga que abrir una ventana de herramientas mediante programación, como el comando que hace el controlador.

Para abrir una ventana de herramientas en el paquete VSPackage administrado que la proporciona, utilice FindToolWindow. Para abrir una ventana de herramientas en otro paquete VSPackage, utilice el FindToolWindow. En cualquier caso, la ventana de herramientas se crea en caso necesario.

El siguiente código se toma del ejemplo de C# Reference.ToolWindow.

Para abrir una ventana de herramientas mediante programación

  1. Crear el panel de la ventana de herramientas, el cuadro, y el Paquete que se implementan. Para obtener más información, vea Cómo: cree una ventana de herramientas.

  2. Registre la ventana de herramientas con Visual Studio agregando ProvideToolWindowAttribute el Paquete que lo proporciona.

    <PackageRegistration(UseManagedResourcesOnly:=True), _
    InstalledProductRegistration("#110", "#112", "1.0", IconResourceID:=400), _
    ProvideMenuResource(1000, 1), _
    ProvideToolWindow(GetType(MyToolWindow), Style:=VsDockStyle.Tabbed, Window:="3ae79031-e1bc-11d0-8f78-00a0c9110057"), _
    DefaultRegistryRoot("Software\Microsoft\VisualStudio\8.0Exp"), _
    Guid("01069CDD-95CE-4620-AC21-DDFF6C57F012")> _
    Public NotInheritable Class PackageToolWindow
        Inherits Package
    
    [ProvideToolWindow(typeof(MyToolWindow), Style = VsDockStyle.Tabbed, Window = "3ae79031-e1bc-11d0-8f78-00a0c9110057")]
    [ProvideMenuResource(1000, 1)]
    [DefaultRegistryRoot(@"Software\Microsoft\VisualStudio\8.0Exp")]
    [PackageRegistration(UseManagedResourcesOnly = true)]
    [Guid("01069CDD-95CE-4620-AC21-DDFF6C57F012")]
    public sealed class PackageToolWindow : Package
    

    Esto registra la ventana de herramientas PersistedWindowPane que se abrirá como se acopla a Explorador de soluciones. Para obtener más información, vea Cómo: registre una ventana de herramientas.

  3. Uso FindToolWindow de encontrar el panel de la ventana de herramientas o de hacerlo si no existe.

    ' Get the (only) instance of this tool window. 
    ' The last flag is set to true so that if the tool window does not exists it will be created. 
    Dim window As ToolWindowPane = Me.FindToolWindow(GetType(MyToolWindow), 0, True)
    If (window Is Nothing) Or (window.Frame Is Nothing) Then 
        Throw New NotSupportedException(Resources.CanNotCreateWindow)
    End If
    
    // Get the (only) instance of this tool window. 
    // The last flag is set to true so that if the tool window does not exists it will be created.
    ToolWindowPane window = this.FindToolWindow(typeof(MyToolWindow), 0, true);
    if ((window == null) || (window.Frame == null))
    {
        throw new NotSupportedException(Resources.CanNotCreateWindow);
    }
    
  4. Obtenga el cuadro de la ventana de herramientas del panel de la ventana de herramientas.

    Dim windowFrame As IVsWindowFrame = TryCast(window.Frame, IVsWindowFrame)
    
    IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;
    
  5. Mostrar la ventana de herramientas.

    ErrorHandler.ThrowOnFailure(windowFrame.Show())
    
    ErrorHandler.ThrowOnFailure(windowFrame.Show());
    

Vea también

Conceptos

VSPackage Essentials