EventDescriptorCollection.Item[] 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取指定的事件。
重载
| 名称 | 说明 |
|---|---|
| Item[Int32] |
获取或设置具有指定索引号的事件。 |
| Item[String] |
获取或设置具有指定名称的事件。 |
Item[Int32]
- Source:
- EventDescriptorCollection.cs
- Source:
- EventDescriptorCollection.cs
- Source:
- EventDescriptorCollection.cs
- Source:
- EventDescriptorCollection.cs
- Source:
- EventDescriptorCollection.cs
获取或设置具有指定索引号的事件。
public:
virtual property System::ComponentModel::EventDescriptor ^ default[int] { System::ComponentModel::EventDescriptor ^ get(int index); };
public virtual System.ComponentModel.EventDescriptor? this[int index] { get; }
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 从零开始的索引号。
属性值
EventDescriptor具有指定索引号的索引号。
例外
index不是有效的索引。Item[Int32]
示例
下面的代码示例使用 Item[] 该属性打印文本框中索引号指定的名称 EventDescriptor 。 由于索引号是从零开始的,本示例打印第二 EventDescriptor个索引号的名称。 它要求 button1 并在 textBox1 窗体上实例化。
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
注解
索引号从零开始。 因此,必须从特定 EventDescriptor 位置减去 1 才能访问该 EventDescriptor数字。 例如,若要获取第三 EventDescriptor个,需要指定 myColl[2]。
另请参阅
适用于
Item[String]
- Source:
- EventDescriptorCollection.cs
- Source:
- EventDescriptorCollection.cs
- Source:
- EventDescriptorCollection.cs
- Source:
- EventDescriptorCollection.cs
- Source:
- EventDescriptorCollection.cs
获取或设置具有指定名称的事件。
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 。
属性值
EventDescriptor具有指定名称或null事件不存在。
示例
下面的代码示例使用 Item[] 属性打印索引所指定的组件的 EventDescriptor 类型。 它要求 button1 并在 textBox1 窗体上实例化。
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[] 属性区分大小写。 也就是说,名称“Ename”和“ename”被视为两个不同的事件。
注释
HostProtectionAttribute应用于此类的属性具有以下Resources属性值: Synchronization 这 HostProtectionAttribute 不会影响桌面应用程序(通常通过双击图标、键入命令或在浏览器中输入 URL 来启动)。 有关详细信息,请参阅 HostProtectionAttribute 类或 SQL Server 编程和主机保护属性。