ToolBoxItem2.Collection 属性
获取包含支持此属性的 ToolBoxItem 对象的集合。
命名空间: EnvDTE80
程序集: EnvDTE80(在 EnvDTE80.dll 中)
语法
声明
ReadOnly Property Collection As ToolBoxItems
ToolBoxItems Collection { get; }
property ToolBoxItems^ Collection {
ToolBoxItems^ get ();
}
abstract Collection : ToolBoxItems with get
function get Collection () : ToolBoxItems
属性值
类型:ToolBoxItems
一个 ToolBoxItems 集合。
示例
此示例选择第二个 ToolBoxItem2 项并在消息框中显示其名称。 此示例还显示包含在第二个工具箱选项卡中的每个工具箱项的名称。 有关如何作为外接程序运行此示例的更多信息,请参见 如何:编译和运行自动化对象模型代码示例。
Imports EnvDTE
Imports EnvDTE80
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)
ToolBoxItemCollectionExample(_applicationObject)
End Sub
Sub ToolBoxItemCollectionExample(ByVal dte As DTE2)
Dim tlBox As ToolBox
Dim tbxTabs As ToolBoxTabs
Dim tbxTab As ToolBoxTab2
Dim tbxItem As ToolBoxItem2
Dim aString As String = "All the toolbox items in the collection: _
" & vbCr
' Before running this example, open a Windows Application project.
Try
' Create an object reference to the IDE's ToolBox object and
' its tabs.
tlBox = CType(_applicationObject.Windows.Item _
(Constants.vsWindowKindToolbox).Object, ToolBox)
tbxTabs = tlBox.ToolBoxTabs
' Select the second ToolBox tab.
tbxTab = CType(tbxTabs.Item(2), ToolBoxTab2)
tbxTab.Activate()
MsgBox("Toolbox tab name: " & tbxTab.Name)
tbxItem = CType(tbxTab.ToolBoxItems.Item(2), ToolBoxItem2)
MsgBox("ToolBox item name: " & tbxItem.Name)
For Each temp As ToolBoxItem2 In tbxItem.Collection
aString = aString & (temp.Name) & vbCr
Next
MsgBox(aString)
Catch ex As System.Exception
MsgBox("ERROR: " & ex.Message)
End Try
End Sub
using EnvDTE;
using EnvDTE80;
using System.Windows.Forms;
public void OnConnection(object application,
ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
ToolBoxItemExample(_applicationObject);
}
public void ToolBoxItemExample(DTE2 dte)
{
ToolBox tlBox;
ToolBoxTabs tbxTabs;
ToolBoxTab2 tbxTab;
ToolBoxItem2 tbxItem;
String aString = "All the toolbox items in the collection:" + "\n";
// Before running this example, open a Windows Application project
// and select Toolbox from the View menu.
try
{
// Create an object reference to the IDE's ToolBox object
// and its tabs.
tlBox = (ToolBox)_applicationObject.Windows.Item
(Constants.vsWindowKindToolbox).Object;
tbxTabs = tlBox.ToolBoxTabs;
// Select the second Toolbox tab.
tbxTab = (ToolBoxTab2)tbxTabs.Item(2);
tbxTab.Activate();
MessageBox.Show("Toolbox tab name: " + tbxTab.Name);
tbxItem = (ToolBoxItem2)tbxTab.ToolBoxItems.Item(2);
MessageBox.Show("ToolBox item name: " + tbxItem.Name);
foreach (ToolBoxItem2 temp in tbxItem.Collection)
{
aString = aString + (temp.Name) + "\n";
}
MessageBox.Show(aString);
}
catch (Exception ex)
{
MessageBox.Show("ERROR: " + ex.Message);
}
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关详细信息,请参阅通过部分受信任的代码使用库。