System.ComponentModel.ReflectEventDescriptor.RemoveEventHandler C# (CSharp) Method

RemoveEventHandler() public method

This will remove the delegate value from the event chain so that it no longer gets events from this component.
public RemoveEventHandler ( object component, Delegate value ) : void
component object
value System.Delegate
return void
        public override void RemoveEventHandler(object component, Delegate value)
        {
            FillMethods();

            if (component != null)
            {
                ISite site = GetSite(component);
                IComponentChangeService changeService = null;

                // Announce that we are about to change this component
                //
                if (site != null)
                {
                    changeService = (IComponentChangeService)site.GetService(typeof(IComponentChangeService));
                }

                if (changeService != null)
                {
                    try {
                        changeService.OnComponentChanging(component, this);
                    }
                    catch (CheckoutException coEx) {
                        if (coEx == CheckoutException.Canceled) {
                            return;
                        }
                        throw coEx;
                    }
                    changeService.OnComponentChanging(component, this);
                }

                bool shadowed = false;

                if (site != null && site.DesignMode)
                {
                    IDictionaryService dict = (IDictionaryService)site.GetService(typeof(IDictionaryService));
                    if (dict != null)
                    {
                        Delegate del = (Delegate)dict.GetValue(this);
                        del = Delegate.Remove(del, value);
                        dict.SetValue(this, del);
                        shadowed = true;
                    }
                }

                if (!shadowed)
                {
                    _removeMethod.Invoke(component, new[] { value });
                }

                // Now notify the change service that the change was successful.
                //
                if (changeService != null)
                {
                    changeService.OnComponentChanged(component, this, null, value);
                }
            }
        }
    }