ToolboxComponentsCreatedEventHandler 委托
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示 ComponentsCreated 事件的处理方法。
public delegate void ToolboxComponentsCreatedEventHandler(System::Object ^ sender, ToolboxComponentsCreatedEventArgs ^ e);
public delegate void ToolboxComponentsCreatedEventHandler(object sender, ToolboxComponentsCreatedEventArgs e);
type ToolboxComponentsCreatedEventHandler = delegate of obj * ToolboxComponentsCreatedEventArgs -> unit
Public Delegate Sub ToolboxComponentsCreatedEventHandler(sender As Object, e As ToolboxComponentsCreatedEventArgs)
参数
- sender
- Object
事件源。
示例
以下示例代码提供了一个方法,该方法为 ComponentsCreatedToolboxItem的事件附加事件处理程序。 它还提供了一个ToolboxComponentsCreatedEventHandler事件处理程序方法,该方法在事件引发ComponentsCreated事件处理程序时,Console将创建的组件类型的名称写入 。
public:
[PermissionSetAttribute(SecurityAction::Demand, Name="FullTrust")]
void LinkToolboxComponentsCreatedEvent( ToolboxItem^ item )
{
item->ComponentsCreated +=
gcnew ToolboxComponentsCreatedEventHandler( this, &Form1::OnComponentsCreated );
}
private:
void OnComponentsCreated( Object^ sender, ToolboxComponentsCreatedEventArgs^ e )
{
// Lists created components on the Console.
for ( int i = 0; i < e->Components->Length; i++ )
{
Console::WriteLine( "Component #" + i + ": " +
e->Components[ i ]->Site->Name );
}
}
public void LinkToolboxComponentsCreatedEvent(ToolboxItem item)
{
item.ComponentsCreated += new ToolboxComponentsCreatedEventHandler(this.OnComponentsCreated);
}
private void OnComponentsCreated(object sender, ToolboxComponentsCreatedEventArgs e)
{
// Lists created components on the Console.
for( int i=0; i< e.Components.Length; i++ )
Console.WriteLine("Component #"+i.ToString()+": "+e.Components[i].Site.Name.ToString());
}
Public Sub LinkToolboxComponentsCreatedEvent(ByVal item As ToolboxItem)
AddHandler item.ComponentsCreated, AddressOf Me.OnComponentsCreated
End Sub
Private Sub OnComponentsCreated(ByVal sender As Object, ByVal e As ToolboxComponentsCreatedEventArgs)
' Lists created components on the Console.
Dim i As Integer
For i = 0 To e.Components.Length - 1
Console.WriteLine(("Component #" + i.ToString() + ": " + e.Components(i).Site.Name.ToString()))
Next i
End Sub
注解
创建 ToolboxComponentsCreatedEventHandler 委托时,需要标识将处理该事件的方法。 若要将事件与事件处理程序关联,请将该委托的一个实例添加到事件中。 除非移除了该委托,否则每当发生该事件时就会调用事件处理程序。 有关事件处理程序委托的详细信息,请参阅 处理和引发事件。
扩展方法
GetMethodInfo(Delegate) |
获取指示指定委托表示的方法的对象。 |