This documentation is archived and is not being maintained.

ToolboxComponentsCreatedEventHandler Delegate

Represents the method that handles the ComponentsCreated event.

[Visual Basic]
<Serializable>
Public Delegate Sub ToolboxComponentsCreatedEventHandler( _
   ByVal sender As Object, _
   ByVal e As ToolboxComponentsCreatedEventArgs _
)
[C#]
[Serializable]
public delegate void ToolboxComponentsCreatedEventHandler(
   object sender,
   ToolboxComponentsCreatedEventArgs e
);
[C++]
[Serializable]
public __gc __delegate void ToolboxComponentsCreatedEventHandler(
   Object* sender,
   ToolboxComponentsCreatedEventArgs* e
);

[JScript] In JScript, you can use the delegates in the .NET Framework, but you cannot define your own.

Parameters [Visual Basic, C#, C++]

The declaration of your event handler must have the same parameters as the ToolboxComponentsCreatedEventHandler delegate declaration.

sender
The source of the event.
e
A ToolboxComponentsCreatedEventArgs that provides data for the event.

Remarks

When you create a ToolboxComponentsCreatedEventHandler delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate. For more information about event-handler delegates, see Events and Delegates.

Example

[Visual Basic, C#, C++] The following example code provides a method that attaches an event handler for the ComponentsCreated event of a ToolboxItem. It also provides a System.Drawing.Design.ToolboxComponentCreatedEventHandler event handler method that writes the name of the type of the components that were created to the Console when the event handler is raised by a ComponentsCreated event.

[Visual Basic] 
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

[C#] 
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());            
}

[C++] 
public:
    void LinkToolboxComponentsCreatedEvent(ToolboxItem* item) {
        item->ComponentsCreated += new 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(S"Component #{0}: {1}", __box(i), e->Components[i]->Site->Name);
    }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Drawing.Design

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Drawing (in System.Drawing.dll)

See Also

System.Drawing.Design Namespace | ToolboxComponentsCreatedEventArgs

Show: