共用方式為


Windows2.Item 方法 (Object)

傳回 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
    型別:System.Object
    必要項。所要傳回項目的索引。

傳回值

型別:EnvDTE.Window
Window 物件。

備註

傳遞給 Index 的值是整數,也就是物件在集合中的索引。 然而對許多物件而言,Index 值也可以是等於集合中之物件的字串值。 但是,Item 接受的實際值,會視集合及其實作而有所不同。

如果集合無法找到對應於索引值的物件,Item 方法就會擲回 ArgumentException 例外狀況。

範例

這個範例會顯示 Windows2 集合中所有項目的標題。

如需如何像執行增益集一般,執行這個範例的詳細資訊,請參閱 HOW TO:編譯和執行 Automation 物件模型程式碼範例

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 介面

Item 多載

EnvDTE80 命名空間

其他資源

HOW TO:編譯和執行 Automation 物件模型程式碼範例