Partager via


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

Mise à jour : novembre 2007

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.

Remarque :

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.

Remarque :

Selon vos paramètres actifs ou votre édition, les boîtes de dialogue et les commandes de menu que vous voyez peuvent différer de celles qui sont décrites dans l'aide. 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 Importer et ExporterParamè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 lient ensemble. Ils montrent également comment dimensionner des fenêtres Outil et en annuler l'ancrage. Pour plus d'informations sur l'exécution de l'exemple de code dans un complément, consultez Comment : compiler et exécuter les exemples de code du modèle objet Automation.

Attention :

L'exécution de cet exemple modifie la disposition de votre fenêtre Outil Visual Studio actuelle.

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