共用方式為


ToolboxComponentsCreatedEventHandler 代理人

定義

代表處理 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 委派時,必須識別處理事件的方法。 若要使事件與您的事件處理常式產生關聯,請將委派的執行個體 (Instance) 加入至事件。 除非您移除委派,否則每當事件發生時就會呼叫事件處理常式。 如需事件處理程式委派的詳細資訊,請參閱 處理和引發事件

擴充方法

GetMethodInfo(Delegate)

取得表示特定委派所代表之方法的物件。

適用於

另請參閱