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); }