Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ComponentChangedEventHandler Delegate

Represents the method that will handle a ComponentChanged event.

[Visual Basic]
<Serializable>
<ComVisible(True)>
Public Delegate Sub ComponentChangedEventHandler( _
   ByVal sender As Object, _
   ByVal e As ComponentChangedEventArgs _
)
[C#]
[Serializable]
[ComVisible(true)]
public delegate void ComponentChangedEventHandler(
   object sender,
   ComponentChangedEventArgs e
);
[C++]
[Serializable]
[ComVisible(true)]
public __gc __delegate void ComponentChangedEventHandler(
   Object* sender,
   ComponentChangedEventArgs* 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 ComponentChangedEventHandler delegate declaration.

sender
The source of the event.
e
A ComponentChangedEventArgs that contains the event data.

Remarks

When you create a ComponentChangedEventHandler 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.

A ComponentChanged event will not occur during the loading or unloading of a form because changes are expected during these operations.

Example

[Visual Basic, C#, C++] This example demonstrates registering a ComponentChangedEventHandler and handling the ComponentChanged event.

[Visual Basic] 
Public Sub LinkComponentChangedEvent(ByVal changeService As IComponentChangeService)
    ' Registers an event handler for the ComponentChanged event.
    AddHandler changeService.ComponentChanged, AddressOf Me.OnComponentChanged
End Sub

Private Sub OnComponentChanged(ByVal sender As Object, ByVal e As ComponentChangedEventArgs)
    ' Displays changed component information on the console.            
    Console.WriteLine(("Type of the component that has changed: " + e.Component.GetType().FullName))
    Console.WriteLine(("Name of the member of the component that has changed: " + e.Member.Name))
    Console.WriteLine(("Old value of the member: " + e.OldValue.ToString()))
    Console.WriteLine(("New value of the member: " + e.NewValue.ToString()))
End Sub

[C#] 
public void LinkComponentChangedEvent(IComponentChangeService changeService)
{
    // Registers an event handler for the ComponentChanged event.
    changeService.ComponentChanged += new ComponentChangedEventHandler(this.OnComponentChanged);            
}

private void OnComponentChanged(object sender, ComponentChangedEventArgs e)
{
    // Displays changed component information on the console.
    Console.WriteLine("Type of the component that has changed: "+e.Component.GetType().FullName);      
    Console.WriteLine("Name of the member of the component that has changed: "+e.Member.Name);            
    Console.WriteLine("Old value of the member: "+e.OldValue.ToString());
    Console.WriteLine("New value of the member: "+e.NewValue.ToString());
}

[C++] 
public:
    void LinkComponentChangedEvent(IComponentChangeService* changeService)
    {
        // Registers an event handler for the ComponentChanged event.
        changeService->ComponentChanged += new ComponentChangedEventHandler(this, &ComponentChangedEventHandlerExample::OnComponentChanged);
    }

private:
    void OnComponentChanged(Object* /*sender*/, ComponentChangedEventArgs* e)
    {
        // Displays changed component information on the console.
        Console::WriteLine(S"Type of the component that has changed: {0}", e->Component->GetType()->FullName);
        Console::WriteLine(S"Name of the member of the component that has changed: {0}", e->Member->Name);
        Console::WriteLine(S"Old value of the member: {0}", e->OldValue);
        Console::WriteLine(S"New value of the member: {0}", e->NewValue);
    }

[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.ComponentModel.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 (in System.dll)

See Also

System.ComponentModel.Design Namespace | ComponentChanged | ComponentChanging | ComponentChangedEventArgs | IComponentChangeService

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft