EventDescriptorCollection.Count 属性

获取集合中事件说明符的数目。

**命名空间:**System.ComponentModel
**程序集:**System(在 system.dll 中)

语法

声明
Public ReadOnly Property Count As Integer
用法
Dim instance As EventDescriptorCollection
Dim value As Integer

value = instance.Count
public int Count { get; }
public:
property int Count {
    int get ();
}
/** @property */
public int get_Count ()
public function get Count () : int

属性值

集合中事件说明符的数目。

备注

Count 属性可用于设置循环访问对象集合的循环的界限。如果集合是从零开始的,务必使用 Count - 1 作为循环的上限。

提示

应用于此类的 HostProtectionAttribute 属性 (Attribute) 具有以下 Resources 属性 (Property) 值:SynchronizationHostProtectionAttribute 不影响桌面应用程序(桌面应用程序一般通过双击图标,键入命令或在浏览器中输入 URL 启动)。有关更多信息,请参见 HostProtectionAttribute 类或 SQL Server 编程和宿主保护属性

示例

下面的代码示例使用 Count 属性来输出附加到 button1 的事件的数目。它要求已在窗体上实例化 button1textBox1

Private Sub GetCount()
    ' Creates a new collection and assigns it the events for button1.
    Dim events As EventDescriptorCollection = TypeDescriptor.GetEvents(button1)
    
    ' Prints the number of events on button1 in a text box.
    textBox1.Text = events.Count.ToString()
End Sub 'GetCount
private void GetCount() {
    // Creates a new collection and assigns it the events for button1.
    EventDescriptorCollection events = TypeDescriptor.GetEvents(button1);
 
    // Prints the number of events on button1 in a text box.
    textBox1.Text = events.Count.ToString();
 }
private:
   void GetCount()
   {
      // Creates a new collection and assigns it the events for button1.
      EventDescriptorCollection^ events = TypeDescriptor::GetEvents( button1 );
      
      // Prints the number of events on button1 in a text box.
      textBox1->Text = events->Count.ToString();
   }
private void GetCount()
{
    // Creates a new collection and assigns it the events for button1.
    EventDescriptorCollection events = TypeDescriptor.GetEvents(button1);

    // Prints the number of events on button1 in a text box.
    textBox1.set_Text(System.Convert.ToString(events.get_Count()));
} //GetCount

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

EventDescriptorCollection 类
EventDescriptorCollection 成员
System.ComponentModel 命名空间
EventDescriptor 类
TypeDescriptor