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. 它要求button1在窗textBox1体中实例化和。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()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

显式界面实现

ICollection.CopyTo(Array, Int32)

将该集合的元素复制到 Array(从特定的 Array 索引开始)。Copies 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.

适用于

另请参阅