Windows2.Item 方法

返回 Windows 集合的一个索引成员。

命名空间:  EnvDTE80
程序集:  EnvDTE80(在 EnvDTE80.dll 中)

语法

声明
Function Item ( _
    index As Object _
) As Window
Window Item(
    Object index
)
Window^ Item(
    [InAttribute] Object^ index
)
abstract Item : 
        index:Object -> Window
function Item(
    index : Object
) : Window

参数

  • index
    类型:Object

    必选。 要返回的项的索引。

返回值

类型:Window
一个 Window 对象。

备注

传递给 Index 的值是一个整数,该整数是某对象在其集合中的索引。 但是对于许多对象,Index 的值还可以是等同于集合对象的字符串值。 但是,Item 接受的精确值取决于集合及其实现。

如果集合找不到对应于索引值的对象,则 Item 方法引发 ArgumentException 异常。

示例

此示例显示 Windows2 集合中所有项的标题。

有关如何作为外接程序运行此示例的更多信息,请参见 如何:编译和运行自动化对象模型代码示例

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)
    IterateItems(_applicationObject)
End Sub
Sub IterateItems(ByVal dte As DTE2)
    Dim win As Windows2
    win = CType(_applicationObject.Windows, EnvDTE80.Windows2)
    Dim aString As String
    aString = ""
    Dim count As Integer
    count = win.Count
    Dim i As Integer
    For i = 1 To count Step 1
        aString = aString & "The window number " & i & _
 " in the collection, has the caption: " & win.Item(i).Caption & vbCr
    Next
    MsgBox(aString)
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;
    IterateItems(_applicationObject);
}
public void IterateItems(DTE2 dte)
{
    Windows2 win;
    win = (EnvDTE80.Windows2)_applicationObject.Windows;
    int count = win.Count;
    String aString = null;
    for (int i = 1; i <= count; i++ )
    {
        aString = aString + ("The window number " + i + 
" in the collection, has the caption: " + win.Item(i).Caption + "\n");
    }
    MessageBox.Show(aString);
}

.NET Framework 安全性

请参阅

参考

Windows2 接口

EnvDTE80 命名空间

其他资源

如何:编译和运行自动化对象模型代码示例