次の方法で共有


WindowConfiguration の選択の例

Visual Studio アドインは、Visual Studio 2013 では使用されなくなりました。 アドインを VSPackage 拡張機能にアップグレードしてください。 アップグレードの詳細については、「FAQ: アドインを VSPackage 拡張に変換する」を参照してください。

次の例は、複数のウィンドウ構成を作成、参照、および削除する方法と、構成を選択および適用する方法を示しています。 この方法により、現在のウィンドウ構成のスナップショットが作成されます。 WinConfigExample2a を実行した後、Visual Studio 環境の一部のウィンドウを移動し、2 番目のプロシージャとして WinConfigExample2b を実行します。 現在のウィンドウ構成の新しいスナップショットが作成され、最初のスナップショットと比較されます。 次に、2 つのウィンドウ構成が削除され、元の環境にリセットされます。

次の例を使用するには、例を新しいアドイン プロジェクトにコピーし、アドインの 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