This is the base for classes that can be hosted in a container such
as those provided by the design-time environment. Note that it is a
marshal-by-reference object. If you need marshal-by-value semantics,
use MarshalByValueComponent.
You can obtain the Container that hosts the
component and the Site that binds the component to
the container. Derived classes also can use the protected
DesignMode property to determine whether the class
is hosted in a designer.
Note that the class implements the IDisposable
interface. The Container ensures that the object
is disposed correctly (if you have a Container,
but you should ensure that your resource release code is added to the
Dispose() method.
There are actually two dispose methods, and you would normally
override the protected member that takes a Boolean. This is to
support different cleanup behavior when Dispose()
is called by the Container, and when it is called
by the Component object's
finalizer.
Typically, Component-derived classes are those
non-windowed classes that you wish to present in the designer
environment. They can use the GetService() method
of the Site to make use of facilities provided by
the designer host.
Classes that display a window should derive instead from
System.Windows.Forms.Control, which itself derives
from Component.
public class Component : MarshalByRefObject : IComponent, IDisposable {
// Public Constructors
public Component();
// Public Instance Properties
public IContainer Container{get; }
public virtual ISite Site{set; get; }
// implements IComponent
// Protected Instance Properties
protected bool DesignMode{get; }
protected EventHandlerList Events{get; }
// Public Instance Methods
public void Dispose(); // implements IDisposable
public override string ToString(); // overrides object
// Protected Instance Methods
protected virtual void Dispose(bool disposing);
protected override void Finalize(); // overrides object
protected virtual object GetService(Type service);
// Events
public event EventHandler Disposed;
// implements IComponent
}