本文整理汇总了C#中IComponent.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# IComponent.Dispose方法的具体用法?C# IComponent.Dispose怎么用?C# IComponent.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IComponent
的用法示例。
在下文中一共展示了IComponent.Dispose方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Remove
public void Remove(IComponent component)
{
if(component==null)
{
throw new ArgumentException("component");
}
// fire off changing and removing event
ComponentEventArgs ce = new ComponentEventArgs(component);
OnComponentChanging(component,null);
try
{
if(ComponentRemoving!=null)
{
ComponentRemoving(this, ce);
}
}
catch
{
// dont throw here
}
// make sure we own the component
if(component.Site!=null && component.Site.Container==this)
{
// remove from extender provider list
if (component is IExtenderProvider)
{
IExtenderProviderService extenderProvider = (IExtenderProviderService)GetService(typeof(IExtenderProviderService));
if(extenderProvider!=null)
{
extenderProvider.RemoveExtenderProvider((IExtenderProvider)component);
}
}
// remove the site
sites.Remove(component.Site.Name);
// dispose the designer
IDesigner designer = designers[component] as IDesigner;
if(designer!=null)
{
designer.Dispose();
// get rid of the designer from the list
designers.Remove(component);
}
// fire off removed event
try
{
if(ComponentRemoved!=null)
{
ComponentRemoved(this, ce);
}
this.OnComponentChanged(component,null,null,null);
}
catch
{
// dont throw here
}
// breakdown component, container, and site relationship
component.Site=null;
// now dispose the of the component too
component.Dispose();
}
}
示例2: DestroyComponent
public void DestroyComponent (IComponent component)
{
if (component.Site != null && component.Site.Container == this) {
OnComponentChanging (component, null);
this.Remove (component); // takes care for the designer as well
component.Dispose ();
OnComponentChanged (component, null, null, null);
}
}
示例3: ArgumentNullException
void IContainer.Remove(IComponent component)
{
if (component == null)
{
throw new ArgumentNullException("component");
}
if (component.Site != null)
{
string name = component.Site.Name;
if ((name != null) && (this.ComponentTable[name] == component))
{
ComponentEventArgs e = new ComponentEventArgs(component);
this.OnComponentRemoving(e);
if (this.DesignerTable != null)
{
IDesigner designer = (IDesigner) this.DesignerTable[component];
if (designer != null)
{
this.DesignerTable.Remove(component);
designer.Dispose();
}
}
this.ComponentTable.Remove(name);
component.Dispose();
try
{
this.OnComponentRemoved(e);
}
catch
{
}
component.Site = null;
}
}
}
示例4: ArgumentNullException
void IDesignerHost.DestroyComponent(IComponent component)
{
string name;
if (component == null)
{
throw new ArgumentNullException("component");
}
if ((component.Site != null) && (component.Site.Name != null))
{
name = component.Site.Name;
}
else
{
name = component.GetType().Name;
}
InheritanceAttribute attribute = (InheritanceAttribute) TypeDescriptor.GetAttributes(component)[typeof(InheritanceAttribute)];
if ((attribute != null) && (attribute.InheritanceLevel != InheritanceLevel.NotInherited))
{
Exception exception = new InvalidOperationException(System.Design.SR.GetString("DesignerHostCantDestroyInheritedComponent", new object[] { name })) {
HelpLink = "DesignerHostCantDestroyInheritedComponent"
};
throw exception;
}
if (((IDesignerHost) this).InTransaction)
{
this.Remove(component);
component.Dispose();
}
else
{
using (DesignerTransaction transaction = ((IDesignerHost) this).CreateTransaction(System.Design.SR.GetString("DesignerHostDestroyComponentTransaction", new object[] { name })))
{
this.Remove(component);
component.Dispose();
transaction.Commit();
}
}
}
示例5: DestroyComponent
/// Destroys the given component, removing it from the design container.
public void DestroyComponent(IComponent comp) {
string name;
if (comp.Site != null && comp.Site.Name != null) {
name = comp.Site.Name;
}
else {
name = comp.GetType().Name;
}
// Make sure the component is not being inherited -- we can't delete these!
InheritanceAttribute ia = (InheritanceAttribute)TypeDescriptor.GetAttributes(comp)[typeof(InheritanceAttribute)];
if (ia != null && ia.InheritanceLevel != InheritanceLevel.NotInherited) {
throw new InvalidOperationException("CantDestroyInheritedComponent" + name);
}
DesignerTransaction t = null;
try {
// We try to remove the component from the container before destroying it.
t = CreateTransaction("DestroyComponentTransaction" + name);
// We need to signal changing and then perform the remove. Remove must be done by us and not
// by Dispose because (a) people need a chance to cancel through a Removing event, and (b)
// Dispose removes from the container last and anything that would sync Removed would end up
// with a dead component.
//
((IComponentChangeService)this).OnComponentChanging(comp, null);
if (comp.Site != null) {
Remove(comp);
}
DeleteDesignedComponent(comp);
comp.Dispose();
((IComponentChangeService)this).OnComponentChanged(comp, null, null, null);
}
finally {
if (t != null) {
t.Commit();
}
}
}
示例6: DestroyComponent
public void DestroyComponent (IComponent component)
{
this.Remove (component); // takes care of the designer as well
component.Dispose ();
}
示例7: DestroyComponent
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 ();
}
示例8: DestroyComponent
public void DestroyComponent(IComponent comp)
{
string name;
if ((comp.Site != null) && (comp.Site.Name != null))
{
name = comp.Site.Name;
}
else
{
name = comp.GetType().Name;
}
InheritanceAttribute ia = (InheritanceAttribute) TypeDescriptor.GetAttributes(comp)[typeof(InheritanceAttribute)];
if ((ia != null) && (ia.InheritanceLevel != InheritanceLevel.NotInherited))
{
throw new InvalidOperationException("CantDestroyInheritedComponent" + name);
}
DesignerTransaction t = null;
try
{
t = this.CreateTransaction("DestroyComponentTransaction" + name);
((IComponentChangeService) this).OnComponentChanging(comp, null);
if (comp.Site != null)
{
this.Remove(comp);
}
comp.Dispose();
((IComponentChangeService) this).OnComponentChanged(comp, null, null, null);
}
finally
{
if (t != null)
{
t.Commit();
}
}
}