AspNetEdit.Editor.ComponentModel.DesignerHost.DestroyComponent C# (CSharp) Метод

DestroyComponent() публичный Метод

public DestroyComponent ( IComponent component ) : void
component IComponent
Результат void
        public void DestroyComponent(IComponent component)
        {
            //deselect it if selected
            ISelectionService sel = this.GetService (typeof (ISelectionService)) as ISelectionService;
            bool found = false;
            if (sel != null)
                foreach (IComponent c in sel.GetSelectedComponents ())
                    if (c == component) {
                        found = true;
                        break;
                    }
            //can't modify selection in loop
            if (found) sel.SetSelectedComponents (null);

            if (component != RootComponent) {
                //remove from component and document
                ((Control) RootComponent).Controls.Remove ((Control) component);
                RootDocument.RemoveControl ((Control)component);
            }

            //remove from container if still sited
            if (component.Site != null)
                container.Remove (component);

            component.Dispose ();
        }

Usage Example

Пример #1
0
        public void Remove(System.ComponentModel.IComponent component)
        {
            //safety checks
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }
            if (component.Site == null || component.Site.Container != this)
            {
                throw new ArgumentException("Component is not sited in this container");
            }

            //broadcast start of removal process
            OnComponentRemoving(component);

            //clean up component and designer
            components.Remove(component);
            IDesigner designer = GetDesigner(component);

            if (designer != null)
            {
                designers.Remove(component);
                designer.Dispose();
            }
            component.Site = null;

            //if someone tries to kill root component, must destroy all children too
            if (component == host.RootComponent)
            {
                //clean everything up
                foreach (System.Web.UI.Control control in Components)
                {
                    host.DestroyComponent(control);
                }
                host.SetRootComponent(null);
                host.Reset();
            }

            //TODO: remove references from referenceManager

            //clean up selection service
            ISelectionService sel = (ISelectionService)this.GetService(typeof(ISelectionService));

            if (sel != null && sel.GetComponentSelected(component))
            {
                sel.SetSelectedComponents(new IComponent[] {});
            }

            //broadcast completion of removal process
            OnComponentRemoved(component);
        }