Share via


Comment : modifier les caractéristiques d'une fenêtre

Les compléments Visual Studio sont déconseillés dans Visual Studio 2013. Vous devriez mettre vos compléments à niveau vers des extensions VSPackage. Pour plus d'informations sur les mises à jour, consultez FAQ : conversion de compléments en extensions VSPackage.

Les fenêtres dans Visual Studio sont représentées dans le modèle Automation par l'objet Window2. À l'aide de ses membres, vous pouvez manipuler les caractéristiques d'une fenêtre, telles que sa hauteur et sa largeur. En utilisant la collection Window2, vous pouvez créer une fenêtre liée, composée de plusieurs fenêtres Outil ancrées ensemble. Leurs membres vous permettent également d'ancrer des fenêtres supplémentaires au frame ou de lever leur ancrage.

Notes

Les fenêtres à lier doivent être visibles.Si l'une des deux fenêtres est masquée, vous obtenez une exception.Vous pouvez afficher des fenêtres à l'aide de la propriété Visible.

La collection Windows2 vous permet également de créer vos propres fenêtres Outil. Pour plus d'informations, consultez Comment : créer et contrôler des fenêtres Outil.

Notes

Les boîtes de dialogue et les commandes de menu qui s'affichent peuvent être différentes de celles qui sont décrites dans l'aide, en fonction de vos paramètres actifs ou de l'édition utilisée.Ces procédures ont été développées avec les paramètres de développement généraux actifs.Pour modifier vos paramètres, sélectionnez Importation et exportationde paramètres dans le menu Outils.Pour plus d'informations, consultez Paramètres Visual Studio.

Exemple

Les exemples suivants montrent comment référencer et utiliser les différents membres du modèle Automation pour manipuler des fenêtres Outil. Ils créent une fenêtre Outil liée et insèrent deux fenêtres Outil Visual Studio, à savoir Explorateur de solutions et Sortie, et les associent. Ils montrent également comment dimensionner des fenêtres Outil et en annuler l'ancrage. Avant d'exécuter ce code, assurez-vous que la propriété « Embed Interop Types » de la référence d'assembly EnvDTE a la valeur False. Pour plus d'informations sur l'exécution de l'exemple de code de macro complémentaire, consultez Comment : compiler et exécuter les exemples de code du modèle objet Automation.

Avertissement

Si vous exécutez cet exemple, la disposition actuelle de votre fenêtre Outil Visual Studio sera modifiée.

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

Voir aussi

Tâches

Comment : créer et contrôler des fenêtres Outil

Comment : créer un complément

Procédure pas à pas : création d'un Assistant

Concepts

Graphique Modèle d'objet Automation

Autres ressources

Création et contrôle de fenêtres d'environnement

Création de compléments et d'Assistants

Guide de référence de l'extensibilité et de l'automation