Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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.

For more information about design-time support, see Design-Time Attributes for Components and Extending Design-Time Support.

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:

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.

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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.