EventDescriptorCollection Class

Definition

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

public ref class EventDescriptorCollection : System::Collections::IList
public class EventDescriptorCollection : System.Collections.IList
[System.Runtime.InteropServices.ComVisible(true)]
public class EventDescriptorCollection : System.Collections.IList
type EventDescriptorCollection = class
    interface ICollection
    interface IEnumerable
    interface IList
type EventDescriptorCollection = class
    interface IList
    interface ICollection
    interface IEnumerable
type EventDescriptorCollection = class
    interface ICollection
    interface IList
    interface IEnumerable
Public Class EventDescriptorCollection
Implements IList
Inheritance
EventDescriptorCollection
Attributes
Implements

Examples

下列程式碼範例會在文字方塊中列印按鈕上的所有事件。The following code example prints all the events on a button in a text box. 它需要在表單上具現化 button1textBox1It 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

Remarks

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[] 屬性,依索引編號或名稱取得特定屬性。Use the Item[] 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.

Constructors

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.

Fields

Empty

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

Properties

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.

Methods

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.

(Inherited from 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.

(Inherited from Object)
GetType()

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

(Inherited from 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.

(Inherited from 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.

(Inherited from Object)

Explicit Interface Implementations

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.

Extension Methods

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.

Applies to

See also