WindowConfiguration 建立範例
此範例示範如何建立、參考以及刪除視窗組態。
若要使用這個範例,請將下列程式碼複製到新的增益集 (Add-In) 專案中,然後在增益集的 OnConnection 方法中執行第一個程序 WinConfigExample1。如需如何在增益集中執行下列程式碼範例的詳細資訊,請參閱 HOW TO:編譯和執行 Automation 物件模型程式碼範例。
範例
' 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);
}