AspNetEdit.Editor.ComponentModel.DesignContainer.Remove C# (CSharp) Метод

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

public Remove ( System component ) : void
component System
Результат void
        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);
        }

Usage Example

Пример #1
0
        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();
        }