Technical Training
VB.NET 2005Table of Contents
VB.NET Creating and Managing Components Part 1
VB.NET Creating and Managing Components Part 1 - Page 2
VB.NET Creating and Managing Components Part 1 - Page 3VB.NET Creating and Managing Components Part 1
VB.NET Creating and Managing Components Part 1
In this tutorial you will learn about Components, Best practices in using Components, Creating Components by extending the UserControl Class, Testing the Control, Creating and implementing Events, Extending a control through Visual Inheritance and Inheriting from a UserControl.
A component is a reusable piece of code in binary form. This code can be reused by inheritance. No class is being inherited. It follows that a containment relationship is defined between the application using the component and the component that is being used. This is different from the relationship that exists between a derived class and a base class.
Components have to interact with each other. They need information about each other. This is achieved by loading the components within self-contained packages called assembly. An assembly contains information about the files on which the component depends and the location of these files. The CLR can use this information to determine the dependencies of a component. The assemblies that are required during the execution of an application are called dependencies.
A class becomes a component when it follows defined standards of interaction. These standards are provided by the IComponent interface. All components derive from Component class. The Component class in turn implements IComponent interface.
Best practices in using components
-
The name of the component to be short and meaningful.
-
The access level for constructors should be implemented as private or public based on the usage is either by the same assembly or different assembly.
-
The base class of all components is Component class. You can also implement IComponent interface to create a component.
-
The namespace structure in an assembly should be according to the internal organization of the component. It is preferable to keep all the components together in separate Namespace.
-
The component will have two type of initialization namely, type initialization and instance initialization.
-
Type initialization is achieved by using a shared constructor and this is done only once in the lifetime of the application.
-
Instance initialization is achieved by using the constructors which are not shared.
-
A component like any other class must implement as many interfaces as needed. They are capable of being called in multiple ways.(polymorphism).
Creating components by extending the UserControl Class
Objects help users control the flow of applications. Objects like buttons and ComboBoxes are controls. Controls can be defined as visual components that are used across applications. Controls that are customized by users are called UserControls. User Controls can have multiple child controls and provide the user with a single interface.
Let us now create a user control.
Open the Visual Studio IDE and select the menu File, Choose New – Project to open a new project Dialog Box

Choose Windows Control Library from the items displayed. Type the name of the project as InterestCalculator. Click on OK.
In the solution Explorer window, right-click UserControl1 and select View Code
You can also change the default name UserControl1 to any name of your choice
The class inherits from the UserControl class by default. If you need to inherit from another existing control, edit the statement Inherits System.Windows.Forms.UserControl to refer to your class.
Save the project.
Enter the following code in to the windows.
Ads
Testing the Control
The control is always used in a container. Therefore you need a windows form to test the control. The Steps for doing this are as follows.
Build the control by clicking Build menu.
Create a new windows application project
In the solution explorer window of the new project, right –click the Reference node. Select Add reference to open the Add reference dialog box.
Add the project with your custom control to the selected Components section in the AddReference DialogBox. To close the Add Reference dialog box.
Add the control to you toolbar
In the dialog box that you have opened select .NET Framework Component tab from the Add Reference Dialog Box.
Choose the ToolBox Item

VB.NET 2005
- VB.NET 2005 Free Training
- The .NET Framework Architecture Part 1
- The .NET Framework Architecture Part 2
- Application Class and Message Class
- Implementing Class Library Object
- Visual Studio.NET Namespaces
- .NET Assemblies
- Differences between VB.NET 1.0 and VB.NET 2.0
- Introducing VB.NET Windows Forms
- Visual Studio Windows Forms Designer
- Exploring the Forms Designer generated code
- Setting and Adding Properties to Windows Form
- Implementing Inheritance
- Event Handling In Visual Basic .NET
- Building Graphical Interface elements
- .NET Common Windows Forms Controls Part 1
- .NET Common Windows Forms Controls Part 2
- Common Controls and Handling Control Events
- DomainUpDown and NumericUpDown Controls
- Dialog Boxes in Visual Basic .NET
- Visual Studio Adding Controls to Windows Form
- VB.NET Validation Controls
- Working with Menu Controls
- VB.NET MDI Applications
- .NET Exceptions
- VB.NET Creating and Managing Components Part 1
- VB.NET Creating and Managing Components Part 2
- Simple Data Binding
- .NET Complex Data Binding
- .NET Data Form Wizard
- Data Manipulation with ADO.NET
- SQL Server Stored Procedures
- SQL Server Ad Hoc Queries
- Finding and Sorting Data in DataSets
- ADO.NET Object Model
- Working with DataSets
- Using XML Data
- Working with File System in .NET
- Creating Web Service
- Instantiating - Invoking Web Services, Creating Proxy Classes with WSDL
- Web Reference and Web Services
- Web Services - SOAP, WSDL, Disco and UDDI
- Web Application Testing in VB.NET 2005
- Web Application Tracing and Debugging
- Working with Legacy Code and COM Components
- ActiveX Controls and Legacy Code
- Windows Application Testing
- VB.NET Windows Application Testing
- Tracing VB.NET Windows Application
- Debugging Windows Applications In Visual Studio.NET 2005
- Deploying Windows Applications In Visual Studio.NET 2005
- Customizing Setup Project in Visual Studio.NET 2005
- Shared Assembly
- Microsoft .NET Creating Installation Components
- The Registry Editor in Visual Studio.NET 2005
- The File Types Editor







