Name
Component
Synopsis
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; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access