WindowConfiguration 创建示例

该示例说明如何创建、引用和删除一个窗口配置。

若要使用该示例,请将下面的代码复制到一个新的外接程序项目中,然后在外接程序的 OnConnection 方法中运行第一个过程 WinConfigExample1。 有关如何在外接程序中运行下面的代码示例的更多信息,请参见 如何:编译和运行自动化对象模型代码示例

示例

' Visual Basic example.
Sub WinConfigExample1(ByVal dte As DTE)
    ' Set references to all necessary objects.
    Dim colWinConfig As WindowConfigurations
    Dim objWinConfig As WindowConfiguration

    colWinConfig = dte.WindowConfigurations
    MsgBox("Number of configurations: " & colWinConfig.Count)
    ' List all saved named window configurations
    FillMsg(colWinConfig)
    ' Create a new window configuration.
    objWinConfig = colWinConfig.Add("NewLayout")
    FillMsg(colWinConfig)
    ' Get rid of the new window configuration
    objWinConfig.Delete()
    MsgBox("Number of configurations: " & colWinConfig.Count)
    FillMsg(colWinConfig)
End Sub

Sub FillMsg(ByVal colWinConfig As Object)
    ' Lists all currently available named window configurations.
    Dim lCtr As Integer
    Dim strMsg As String

    For lCtr = 1 To colWinConfig.Count
    strMsg = strMsg & "Configuration name " & lCtr & ": " & _
    colWinConfig.Item(lCtr).Name & vbCr
    Next lCtr
    strMsg = "Current Configurations: " & vbCr & strMsg
    MsgBox(strMsg)
End Sub
void WinConfigExample1(_DTE dte)
{
    //Set references to all necessary objects.
    WindowConfigurations colWinConfig; 
    WindowConfiguration objWinConfig;

    colWinConfig = dte.WindowConfigurations;
    MessageBox.Show("Number of configurations: " + 
    colWinConfig.Count);

    // List all saved named window configurations.
    FillMsg(colWinConfig);
    //Create a new window configuration.
    objWinConfig = colWinConfig.Add("NewLayout");
    FillMsg(colWinConfig);
    // Delete the new window configuration.
    objWinConfig.Delete();
    MessageBox.Show("Number of configurations: " + 
    colWinConfig.Count);
    FillMsg(colWinConfig);
}

void FillMsg(WindowConfigurations colWinConfig )
{
    // Lists all currently available named window configurations.
    int lCtr;
    string strMsg = null;

    for (lCtr = 1; lCtr < colWinConfig.Count + 1; lCtr ++)
    {
        strMsg = strMsg + "Configuration name " + lCtr + ": " + 
        colWinConfig.Item(lCtr).Name + "\n"; 
    }
    strMsg = "Current Configurations: \n" + strMsg;
    MessageBox.Show(strMsg);
}

请参见

参考

WindowConfiguration

WindowConfigurations