EventDescriptorCollection 類別

定義

表示 EventDescriptor 物件的集合。Represents a collection of EventDescriptor objects.

public ref class EventDescriptorCollection : System::Collections::IList
[System.Runtime.InteropServices.ComVisible(true)]
public class EventDescriptorCollection : System.Collections.IList
type EventDescriptorCollection = class
    interface ICollection
    interface IList
    interface IEnumerable
Public Class EventDescriptorCollection
Implements IList
繼承
EventDescriptorCollection
屬性
實作

範例

下列程式碼範例會在文字方塊中列印按鈕上的所有事件。The following code example prints all the events on a button in a text box. 它需要button1textBox1已經在表單上具現化。It requires that button1 and textBox1 have been instantiated on a form.

private:
   void MyEventCollection()
   {
      // Creates a new collection and assigns it the events for button1.
      EventDescriptorCollection^ events = TypeDescriptor::GetEvents( button1 );
      
      // Displays each event in the collection in a text box.
      for each ( EventDescriptor^ myEvent in events )
      {
         textBox1->Text = String::Concat( textBox1->Text, myEvent->Name, "\n" );
      }
   }
private void MyEventCollection() {
    // Creates a new collection and assigns it the events for button1.
    EventDescriptorCollection events = TypeDescriptor.GetEvents(button1);
 
    // Displays each event in the collection in a text box.
    foreach (EventDescriptor myEvent in events)
       textBox1.Text += myEvent.Name + '\n';
 }

Private Sub MyEventCollection()
    ' Creates a new collection and assigns it the events for button1.
    Dim events As EventDescriptorCollection = TypeDescriptor.GetEvents(button1)
    
    ' Displays each event in the collection in a text box.
    Dim myEvent As EventDescriptor
    For Each myEvent In  events
        textBox1.Text &= myEvent.Name & ControlChars.Cr
    Next myEvent
End Sub

備註

EventDescriptorCollection是唯讀的;它不會執行新增或移除事件的方法。EventDescriptorCollection is read-only; it does not implement methods that add or remove events. 您必須繼承自這個類別,才能執行這些方法。You must inherit from this class to implement these methods.

您可以使用EventDescriptorCollection類別中的可用屬性,查詢其內容的集合。Using the properties available in the EventDescriptorCollection class, you can query the collection about its contents. 使用 Count 屬性,判斷集合中的項目數目。Use the Count property to determine the number of elements in the collection. Item[String]使用屬性,依索引編號或名稱取得特定屬性。Use the Item[String] property to get a specific property by index number or by name.

您也可以使用Find方法,從集合中取得具有指定名稱之事件的描述。You can also use the Find method to get a description of the event with the specified name from the collection.

建構函式

EventDescriptorCollection(EventDescriptor[])

使用 EventDescriptorCollection 物件的指定陣列,初始化 EventDescriptor 類別的新執行個體。Initializes a new instance of the EventDescriptorCollection class with the given array of EventDescriptor objects.

EventDescriptorCollection(EventDescriptor[], Boolean)

使用 EventDescriptorCollection 物件的指定陣列,初始化 EventDescriptor 類別的新執行個體。Initializes a new instance of the EventDescriptorCollection class with the given array of EventDescriptor objects. 可選擇將集合設為唯讀。The collection is optionally read-only.

欄位

Empty

指定要使用的空集合,而非建立沒有項目的新集合。Specifies an empty collection to use, rather than creating a new one with no items. 這個 static 欄位是唯讀的。This static field is read-only.

屬性

Count

取得這個集合中事件描述項的數目。Gets the number of event descriptors in the collection.

Item[Int32]

取得或設定具有指定索引編號的事件。Gets or sets the event with the specified index number.

Item[String]

取得或設定具有指定名稱的事件。Gets or sets the event with the specified name.

方法

Add(EventDescriptor)

EventDescriptor 加入集合的結尾。Adds an EventDescriptor to the end of the collection.

Clear()

從集合中移除所有物件。Removes all objects from the collection.

Contains(EventDescriptor)

傳回值,表示集合是否含有指定的 EventDescriptorReturns whether the collection contains the given EventDescriptor.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
Find(String, Boolean)

使用集合中之指定名稱取得事件的描述。Gets the description of the event with the specified name in the collection.

GetEnumerator()

取得這個 EventDescriptorCollection 的列舉值。Gets an enumerator for this EventDescriptorCollection.

GetHashCode()

作為預設雜湊函數。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
IndexOf(EventDescriptor)

傳回指定 EventDescriptor 的索引。Returns the index of the given EventDescriptor.

Insert(Int32, EventDescriptor)

EventDescriptor 插入在指定索引處的集合。Inserts an EventDescriptor to the collection at a specified index.

InternalSort(IComparer)

使用指定的 EventDescriptorCollection,排序這個 IComparer 的成員。Sorts the members of this EventDescriptorCollection, using the specified IComparer.

InternalSort(String[])

排序這個 EventDescriptorCollection 的成員。Sorts the members of this EventDescriptorCollection. 首先會套用指定的順序,其後是這個集合的預設排序,通常是依字母順序。The specified order is applied first, followed by the default sort for this collection, which is usually alphabetical.

MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
Remove(EventDescriptor)

從集合移除指定的 EventDescriptorRemoves the specified EventDescriptor from the collection.

RemoveAt(Int32)

從集合中移除指定索引處的 EventDescriptorRemoves the EventDescriptor at the specified index from the collection.

Sort()

使用這個集合的預設排序,通常是依字母順序,排序這個 EventDescriptorCollection 的成員。Sorts the members of this EventDescriptorCollection, using the default sort for this collection, which is usually alphabetical.

Sort(IComparer)

使用指定的 EventDescriptorCollection,排序這個 IComparer 的成員。Sorts the members of this EventDescriptorCollection, using the specified IComparer.

Sort(String[])

提供指定的排序順序,排序這個 EventDescriptorCollection 的成員。Sorts the members of this EventDescriptorCollection, given a specified sort order.

Sort(String[], IComparer)

提供指定的排序順序和 EventDescriptorCollection,排序這個 IComparer 的成員。Sorts the members of this EventDescriptorCollection, given a specified sort order and an IComparer.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

明確介面實作

ICollection.CopyTo(Array, Int32)

從特定的 Array 索引處開始,將集合元素複製至 ArrayCopies the elements of the collection to an Array, starting at a particular Array index.

ICollection.Count

取得集合所包含的項目數目。Gets the number of elements contained in the collection.

ICollection.IsSynchronized

取得值,表示對集合的存取是否為同步的。Gets a value indicating whether access to the collection is synchronized.

ICollection.SyncRoot

取得物件,這個物件可以用來對集合進行同步存取。Gets an object that can be used to synchronize access to the collection.

IEnumerable.GetEnumerator()

傳回逐一查看集合的列舉值。Returns an enumerator that iterates through a collection.

IList.Add(Object)

將項目加入至集合。Adds an item to the collection.

IList.Clear()

從集合中移除所有項目。Removes all the items from the collection.

IList.Contains(Object)

判斷此集合是否包含特定的值。Determines whether the collection contains a specific value.

IList.IndexOf(Object)

決定集合中指定項目的索引。Determines the index of a specific item in the collection.

IList.Insert(Int32, Object)

將項目插入至集合中的指定索引處。Inserts an item to the collection at the specified index.

IList.IsFixedSize

取得值,這個值表示集合的大小是否是固定的。Gets a value indicating whether the collection has a fixed size.

IList.IsReadOnly

取得值,表示集合是否為唯讀。Gets a value indicating whether the collection is read-only.

IList.Item[Int32]

在指定的索引位置上取得或設定項目。Gets or sets the element at the specified index.

IList.Remove(Object)

從集合中移除第一個出現的特定物件。Removes the first occurrence of a specific object from the collection.

IList.RemoveAt(Int32)

移除在指定索引處的項目。Removes the item at the specified index.

擴充方法

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

啟用查詢的平行化作業。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryableConverts an IEnumerable to an IQueryable.

適用於

另請參閱