共用方式為


HOW TO:變更視窗特性

更新:2007 年 11 月

Visual Studio 中的視窗在 Automation 模型中是以 Window2 物件來表示。您可以使用該物件的成員管理視窗的特性,例如寬度、高度、可視性等。您也可以使用 Window2 集合,建立由兩或多個停駐在一起的工具視窗所組成的連結視窗。其成員也可以讓您將其他視窗停駐於框架 (Frame),或是從框架卸除其他視窗。

注意事項:

要連結的視窗必須是可見的。如果隱藏了其中一個視窗,將會收到例外狀況。您可以使用 Visible 屬性來顯示視窗。

Windows2 集合也可以讓您建立自己的工具視窗。如需詳細資訊,請參閱 HOW TO:建立並控制工具視窗

注意事項:

根據目前使用的設定與版本,您所看到的對話方塊與功能表命令可能會與 [說明] 中所描述的不同。使用 [一般開發設定] 開發了這些程序。若要變更設定,請從 [工具] 功能表中選擇 [匯入和匯出設定]。如需詳細資訊,請參閱 Visual Studio 設定

範例

在下列範例中,會示範如何參考及使用 Automation 模型的各個成員管理工具視窗。在這些範例中,會建立一個連結的工具視窗,以及插入兩個 Visual Studio 工具視窗 (即 [方案總管] 和 [輸出] 視窗),並將這兩個視窗連結在一起,同時也會說明如何調整及卸除工具視窗。如需如何在增益集 (Add-In) 中執行範例程式碼的詳細資訊,請參閱 HOW TO:編譯和執行 Automation 物件模型程式碼範例

警告:

執行這個範例將會變更目前的 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);
}

請參閱

工作

HOW TO:建立並控制工具視窗

HOW TO:建立增益集

逐步解說:建立精靈

概念

Automation 物件模型圖表

其他資源

建立和控制環境視窗

建立增益集和精靈

Automation 與擴充性參考