Share via


WindowConfiguration 선택 예제

Visual Studio의 추가 기능은 Visual Studio 2013에서 사용되지 않습니다. 추가 기능을 VSPackage 확장으로 업그레이드하는 것이 좋습니다. 업그레이드에 대한 자세한 내용은 FAQ: VSPackage 확장으로 추가 기능 변환 을 참조하십시오.

이 예제에서는 여러 개의 창 구성을 작성, 참조 및 삭제하는 방법과 이를 선택 및 적용하는 방법을 보여 줍니다. 이 예제에는 현재 창 구성의 스냅숏이 사용됩니다. WinConfigExample2a를 실행한 후에 Visual Studio 환경의 창 일부를 옮기고 두 번째 프로시저인 WinConfigExample2b를 실행합니다. 이 과정에서 현재 창 구성의 다른 스냅숏을 가져와 이를 첫 번째 스냅숏과 비교합니다. 그런 다음 두 창 구성을 모두 삭제하고 환경을 원래대로 재설정합니다.

다음 예제를 사용하려면 이를 새 추가 기능 프로젝트에 복사하고 추가 기능의 OnConnection 메서드에서 첫 번째 프로시저인 WinConfigExample2a를 실행합니다. 추가 기능의 일부로서 코드 샘플을 실행하는 방법에 대한 자세한 내용은 방법: 자동화 개체 모델 코드의 예제 컴파일 및 실행을 참조하십시오.

예제

Sub WinConfigExample2a(ByVal dte As DTE)
    Dim colWinConfig As WindowConfigurations = dte.WindowConfigurations
    Dim objWinConfig As WindowConfiguration

    MsgBox("Taking snapshot of current window configuration... ")
    objWinConfig = colWinConfig.Add("Layout_1")
    MsgBox("Created new configuration: " & _
    colWinConfig.Item(colWinConfig.Count).Name)
    FillMsg(colWinConfig)
End Sub

Sub WinConfigExample2b(ByVal dte As DTE)
    ' Before running this, alter the current window configuration.
    Dim colWinConfig As WindowConfigurations = dte.WindowConfigurations
    Dim objWinConfig As WindowConfiguration
    Dim lCtr As Integer

    ' Create another new window configuration.
    MsgBox("Now we'll save the new configuration...")
    objWinConfig = colWinConfig.Add("Layout_2")

    MsgBox("Created new configuration: " & _
    colWinConfig.Item(colWinConfig.Count).Name)
    FillMsg(colWinConfig)
    MsgBox("Now we'll load and apply the Layout_1 configuration." & _
    vbCr & "You should see the windows change back.")
    colWinConfig.Item(colWinConfig.Count - 1).Apply()
    MsgBox("Now we'll change back to Layout_2...")
    colWinConfig.Item(colWinConfig.Count).Apply()

    ' Delete both new window configurations.
    colWinConfig.Item(3).Apply()
    For lCtr = (colWinConfig.Count - 1) To (colWinConfig.Count)
        objWinConfig = colWinConfig.Item(colWinConfig.Count)
        objWinConfig.Delete()
        FillMsg(colWinConfig)
    Next lCtr
 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 WinConfigExample2a(_DTE dte)
{
    WindowConfigurations colWinConfig = dte.WindowConfigurations;
    WindowConfiguration objWinConfig;

    MessageBox.Show("Taking snapshot of current window 
    configuration... ");
    objWinConfig = colWinConfig.Add("Layout_1");
    MessageBox.Show("Created new configuration: " + 
    colWinConfig.Item(colWinConfig.Count).Name);
    FillMsg(colWinConfig);
}

void WinConfigExample2b(_DTE dte)
{
    // Before running this, alter the current window configuration.
    WindowConfigurations colWinConfig = dte.WindowConfigurations;
    WindowConfiguration objWinConfig; 
    int lCtr;

    // Create another new window configuration.
    MessageBox.Show("Now we'll save the new configuration...");
    objWinConfig = colWinConfig.Add("Layout_2");

    MessageBox.Show("Created new configuration: " + 
    colWinConfig.Item(colWinConfig.Count).Name);
    FillMsg(colWinConfig);
    MessageBox.Show("Now we'll load and apply the Layout_1 
    configuration. \n You should see the windows change back.");
    colWinConfig.Item(colWinConfig.Count - 1).Apply(true);
    MessageBox.Show("Now we'll change back to Layout_2...");
    colWinConfig.Item(colWinConfig.Count).Apply(true);

    // Delete both new window configurations.
    colWinConfig.Item(3).Apply(true);
    for (lCtr = (colWinConfig.Count - 1); lCtr < (colWinConfig.Count 
    +1); lCtr++)
    {
        objWinConfig = colWinConfig.Item(colWinConfig.Count);
        objWinConfig.Delete();
        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