|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
Creating and Using Components in Visual Basic
A component is a class that implements the System.ComponentModel.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.
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.
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:
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.
LicenseProvider. The abstract base class for implementing a license provider.
Classes commonly used for describing and persisting components.