Creating and Using Components in Visual Basic
A component is a class that implements the IComponent interface or that derives directly or indirectly from a class that implements IComponent. A .NET Framework component is an object that is reusable, can interact with other objects, and provides control over external resources and design-time support.
An important feature of components is that they are designable, which means that a class that is a component can be used in the Visual Studio Integrated Development Environment. A component can be added to the Toolbox, dragged and dropped onto a form, and manipulated on a design surface. Notice that base design-time support for components is built into the .NET Framework; a component developer does not have to do any additional work to take advantage of the base design-time functionality.
A control is similar to a component, as both are designable. However, a control provides a user interface, while a component does not. A control must derive from one of the base control classes: Control or Control.
When to Create a Component
If your class will be used on a design surface (such as the Windows Forms or Web Forms Designer) but has no user interface, it should be a component and implement IComponent, or derive from a class that directly or indirectly implements IComponent.
The Component and MarshalByValueComponent classes are base implementations of the IComponent interface. The main difference between these classes is that the Component class is marshaled by reference, while IComponent is marshaled by value. The following list provides broad guidelines for implementers.
If your component needs to be marshaled by reference, derive from Component.
If your component needs to be marshaled by value, derive from MarshalByValueComponent.
If your component cannot derive from one of the base implementations due to single inheritance, implement IComponent.
For more information about design-time support, see Design-Time Attributes for Components and Extending Design-Time Support.
Component Classes
The System.ComponentModel namespace provides classes that are used to implement the run-time and design-time behavior of components and controls. This namespace includes the base classes and interfaces for implementing attributes and type converters, binding to data sources, and licensing components.
The core component classes are:
Component. A base implementation for the IComponent interface. This class enables object sharing between applications.
MarshalByValueComponent. A base implementation for the IComponent interface.
Container. The base implementation for the IContainer interface. This class encapsulates zero or more components.
Some of the classes used for component licensing are:
License. The abstract base class for all licenses. A license is granted to a specific instance of a component.
LicenseManager. Provides properties and methods to add a license to a component and to manage a LicenseProvider.
LicenseProvider. The abstract base class for implementing a license provider.
LicenseProviderAttribute. Specifies the LicenseProvider class to use with a class.
Classes commonly used for describing and persisting components.
TypeDescriptor. Provides information about the characteristics for a component, such as its attributes, properties, and events.
EventDescriptor. Provides information about an event.
PropertyDescriptor. Provides information about a property.
Related Sections
Class vs. Component vs. Control
Defines component and control, and discusses the differences between them and classes.Component Authoring
Roadmap for getting started with components.Component Authoring Walkthroughs
Links to topics that provide step-by-step instruction for component programming.Component Classes
Describes what makes a class a component, ways to expose component functionality, controlling access to components, and controlling how component instances are created.Troubleshooting Control and Component Authoring
Explains how to fix common problems.
See Also
Tasks
How to: Access Design-Time Support in Windows Forms
How to: Extend the Appearance and Behavior of Controls in Design Mode
How to: Perform Custom Initialization for Controls in Design Mode