EventDescriptorCollection.Item[] 属性
定义
获取指定的事件。Gets the specified event.
重载
| Item[Int32] |
获取或设置具有指定索引号的事件。Gets or sets the event with the specified index number. |
| Item[String] |
获取或设置具有指定名称的事件。Gets or sets the event with the specified name. |
Item[Int32]
获取或设置具有指定索引号的事件。Gets or sets the event with the specified index number.
public:
virtual property System::ComponentModel::EventDescriptor ^ default[int] { System::ComponentModel::EventDescriptor ^ get(int index); };
public virtual System.ComponentModel.EventDescriptor this[int index] { get; }
member this.Item(int) : System.ComponentModel.EventDescriptor
Default Public Overridable ReadOnly Property Item(index As Integer) As EventDescriptor
参数
- index
- Int32
要获取或设置的 EventDescriptor 的从零开始的索引号。The zero-based index number of the EventDescriptor to get or set.
属性值
具有指定索引号的 EventDescriptor。The EventDescriptor with the specified index number.
例外
index 不是 Item[Int32] 的有效索引。index is not a valid index for Item[Int32].
示例
下面的代码示例使用 Item[] 属性 EventDescriptor 在文本框中打印索引号所指定的名称。The following code example uses the Item[] property to print the name of the EventDescriptor specified by the index number in a text box. 由于索引号从零开始,因此,此示例将打印第二个的名称 EventDescriptor 。Because the index number is zero-based, this example prints the name of the second EventDescriptor. 它要求 button1 textBox1 在窗体中实例化和。It requires that button1 and textBox1 have been instantiated on a form.
private:
void PrintIndexItem()
{
// Creates a new collection and assigns it the events for button1.
EventDescriptorCollection^ events = TypeDescriptor::GetEvents( button1 );
// Prints the second event's name.
textBox1->Text = events[ 1 ]->ToString();
}
private void PrintIndexItem() {
// Creates a new collection and assigns it the events for button1.
EventDescriptorCollection events = TypeDescriptor.GetEvents(button1);
// Prints the second event's name.
textBox1.Text = events[1].ToString();
}
Private Sub PrintIndexItem()
' Creates a new collection and assigns it the events for button1.
Dim events As EventDescriptorCollection = TypeDescriptor.GetEvents(button1)
' Prints the second event's name.
textBox1.Text = events(1).ToString()
End Sub
注解
索引号从零开始。The index number is zero-based. 因此,必须从一个特定的数字位置减去 1 EventDescriptor 才能访问该数字 EventDescriptor 。Therefore, you must subtract 1 from the numerical position of a particular EventDescriptor to access that EventDescriptor. 例如,若要获取第三个 EventDescriptor ,需要指定 myColl[2] 。For example, to get the third EventDescriptor, you need to specify myColl[2].
另请参阅
适用于
Item[String]
获取或设置具有指定名称的事件。Gets or sets the event with the specified name.
public:
virtual property System::ComponentModel::EventDescriptor ^ default[System::String ^] { System::ComponentModel::EventDescriptor ^ get(System::String ^ name); };
public virtual System.ComponentModel.EventDescriptor this[string name] { get; }
member this.Item(string) : System.ComponentModel.EventDescriptor
Default Public Overridable ReadOnly Property Item(name As String) As EventDescriptor
参数
- name
- String
要获取或设置的 EventDescriptor 的名称。The name of the EventDescriptor to get or set.
属性值
具有指定名称的 EventDescriptor,或者如果该事件不存在,则为 null。The EventDescriptor with the specified name, or null if the event does not exist.
示例
下面的代码示例使用 Item[] 属性打印索引指定的组件的类型 EventDescriptor 。The following code example uses the Item[] property to print the type of the component for the EventDescriptor specified by the index. 它要求 button1 textBox1 在窗体中实例化和。It requires that button1 and textBox1 have been instantiated on a form.
private:
void PrintIndexItem2()
{
// Creates a new collection and assigns it the events for button1.
EventDescriptorCollection^ events = TypeDescriptor::GetEvents( button1 );
// Sets an EventDescriptor to the specific event.
EventDescriptor^ myEvent = events[ "KeyDown" ];
// Prints the name of the event.
textBox1->Text = myEvent->Name;
}
private void PrintIndexItem2() {
// Creates a new collection and assigns it the events for button1.
EventDescriptorCollection events = TypeDescriptor.GetEvents(button1);
// Sets an EventDescriptor to the specific event.
EventDescriptor myEvent = events["KeyDown"];
// Prints the name of the event.
textBox1.Text = myEvent.Name;
}
Private Sub PrintIndexItem2()
' Creates a new collection and assigns it the events for button1.
Dim events As EventDescriptorCollection = TypeDescriptor.GetEvents(button1)
' Sets an EventDescriptor to the specific event.
Dim myEvent As EventDescriptor = events("KeyDown")
' Prints the name of the event.
textBox1.Text = myEvent.Name
End Sub
注解
Item[]搜索名称时,属性区分大小写。The Item[] property is case-sensitive when searching for names. 也就是说,名称 "Ename" 和 "Ename" 被视为两个不同的事件。That is, the names "Ename" and "ename" are considered to be two different events.
备注
HostProtectionAttribute应用于此类的特性具有以下 Resources 属性值: Synchronization 。The HostProtectionAttribute attribute applied to this class has the following Resources property value: Synchronization. HostProtectionAttribute 不影响桌面应用程序(通常通过双击图标、键入命令或在浏览器中输入 URL 来启动这些应用程序)。The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). 有关详细信息,请参阅 HostProtectionAttribute 类或 SQL Server 编程和宿主保护特性。For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.