ComponentFactory.Krypton.Toolkit.KryptonMonthCalendarDesigner.OnComponentRemoving C# (CSharp) Method

OnComponentRemoving() private method

private OnComponentRemoving ( object sender, ComponentEventArgs e ) : void
sender object
e System.ComponentModel.Design.ComponentEventArgs
return void
        private void OnComponentRemoving(object sender, ComponentEventArgs e)
        {
            // If our control is being removed
            if (e.Component == _monthCalendar)
            {
                // Need access to host in order to delete a component
                IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));

                // We need to remove all the button spec instances
                for (int i = _monthCalendar.ButtonSpecs.Count - 1; i >= 0; i--)
                {
                    // Get access to the indexed button spec
                    ButtonSpec spec = _monthCalendar.ButtonSpecs[i];

                    // Must wrap button spec removal in change notifications
                    _changeService.OnComponentChanging(_monthCalendar, null);

                    // Perform actual removal of button spec from calendar
                    _monthCalendar.ButtonSpecs.Remove(spec);

                    // Get host to remove it from design time
                    host.DestroyComponent(spec);

                    // Must wrap button spec removal in change notifications
                    _changeService.OnComponentChanged(_monthCalendar, null, null, null);
                }
            }
        }