EventDescriptorCollection 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示 EventDescriptor 对象集合。
public ref class EventDescriptorCollection : System::Collections::IListpublic class EventDescriptorCollection : System.Collections.IList[System.Runtime.InteropServices.ComVisible(true)]
public class EventDescriptorCollection : System.Collections.IListtype EventDescriptorCollection = class
    interface ICollection
    interface IEnumerable
    interface IList[<System.Runtime.InteropServices.ComVisible(true)>]
type EventDescriptorCollection = class
    interface IList
    interface ICollection
    interface IEnumerable[<System.Runtime.InteropServices.ComVisible(true)>]
type EventDescriptorCollection = class
    interface ICollection
    interface IEnumerable
    interface IListPublic Class EventDescriptorCollection
Implements IList- 继承
- 
				EventDescriptorCollection
- 属性
- 实现
示例
下面的代码示例在文本框中打印按钮上的所有事件。 它要求 button1 和 textBox1 已在窗体上实例化。
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 可用的属性,可以查询集合中的内容。 使用 Count 属性可确定集合中的元素数。 Item[]使用 属性可按索引号或名称获取特定属性。
还可以使用 Find 方法从集合中获取具有指定名称的事件的说明。
构造函数
| EventDescriptorCollection(EventDescriptor[]) | 用给定的 EventDescriptorCollection 对象的数组初始化 EventDescriptor 类的新实例。 | 
| EventDescriptorCollection(EventDescriptor[], Boolean) | 用给定的 EventDescriptorCollection 对象的数组初始化 EventDescriptor 类的新实例。 该集合可以是只读的。 | 
字段
| Empty | 指定要使用的空集合,而不是创建不具有任何项的新集合。 此  | 
属性
| Count | 获取集合中事件说明符的数目。 | 
| Item[Int32] | 获取或设置具有指定索引号的事件。 | 
| Item[String] | 获取或设置具有指定名称的事件。 | 
方法
显式接口实现
| ICollection.CopyTo(Array, Int32) | |
| ICollection.Count | 获取集合中包含的元素数。 | 
| ICollection.IsSynchronized | 获取一个值,该值指示是否同步对集合的访问。 | 
| ICollection.SyncRoot | 获取可用于同步对集合的访问的对象。 | 
| IEnumerable.GetEnumerator() | 返回循环访问集合的枚举数。 | 
| IList.Add(Object) | 向集合中添加一项。 | 
| IList.Clear() | 从集合中移除所有项。 | 
| IList.Contains(Object) | 确定集合中是否包含特定值。 | 
| IList.IndexOf(Object) | 确定集合中特定项的索引。 | 
| IList.Insert(Int32, Object) | 将某个项插入到集合中的指定索引处。 | 
| IList.IsFixedSize | 获取一个值,该值指示集合是否具有固定大小。 | 
| IList.IsReadOnly | 获取一个值,该值指示集合是否为只读。 | 
| IList.Item[Int32] | 获取或设置指定索引处的元素。 | 
| IList.Remove(Object) | 从集合中移除特定对象的第一个匹配项。 | 
| IList.RemoveAt(Int32) | 删除指定索引处的项。 | 
扩展方法
| Cast<TResult>(IEnumerable) | 将 IEnumerable 的元素强制转换为指定的类型。 | 
| OfType<TResult>(IEnumerable) | 根据指定类型筛选 IEnumerable 的元素。 | 
| AsParallel(IEnumerable) | 启用查询的并行化。 | 
| AsQueryable(IEnumerable) | 将 IEnumerable 转换为 IQueryable。 |