Exforsys

VB.NET 2005

  1. VB.NET 2005 Free Training
  2. The .NET Framework Architecture Part 1
  3. The .NET Framework Architecture Part 2
  4. Application Class and Message Class
  5. Implementing Class Library Object
  6. Visual Studio.NET Namespaces
  7. .NET Assemblies
  8. Differences between VB.NET 1.0 and VB.NET 2.0
  9. Introducing VB.NET Windows Forms
  10. Visual Studio Windows Forms Designer
  11. Exploring the Forms Designer generated code
  12. Setting and Adding Properties to Windows Form
  13. Implementing Inheritance
  14. Event Handling In Visual Basic .NET
  15. Building Graphical Interface elements
  16. .NET Common Windows Forms Controls Part 1
  17. .NET Common Windows Forms Controls Part 2
  18. Common Controls and Handling Control Events
  19. DomainUpDown and NumericUpDown Controls
  20. Dialog Boxes in Visual Basic .NET
  21. Visual Studio Adding Controls to Windows Form
  22. VB.NET Validation Controls
  23. Working with Menu Controls
  24. VB.NET MDI Applications
  25. .NET Exceptions
  26. VB.NET Creating and Managing Components Part 1
  27. VB.NET Creating and Managing Components Part 2
  28. Simple Data Binding
  29. .NET Complex Data Binding
  30. .NET Data Form Wizard
  31. Data Manipulation with ADO.NET
  32. SQL Server Stored Procedures
  33. SQL Server Ad Hoc Queries
  34. Finding and Sorting Data in DataSets
  35. ADO.NET Object Model
  36. Working with DataSets
  37. Using XML Data
  38. Working with File System in .NET
  39. Creating Web Service
  40. Instantiating - Invoking Web Services, Creating Proxy Classes with WSDL
  41. Web Reference and Web Services
  42. Web Services - SOAP, WSDL, Disco and UDDI
  43. Web Application Testing in VB.NET 2005
  44. Web Application Tracing and Debugging
  45. Working with Legacy Code and COM Components
  46. ActiveX Controls and Legacy Code
  47. Windows Application Testing
  48. VB.NET Windows Application Testing
  49. Tracing VB.NET Windows Application
  50. Debugging Windows Applications In Visual Studio.NET 2005
  51. Deploying Windows Applications In Visual Studio.NET 2005
  52. Customizing Setup Project in Visual Studio.NET 2005
  53. Shared Assembly
  54. Microsoft .NET Creating Installation Components
  55. The Registry Editor in Visual Studio.NET 2005
  56. The File Types Editor

Ads


Home arrow Technical Training arrow VB.NET 2005

VB.NET Creating and Managing Components Part 1

Page 1 of 3
Author : Exforsys Inc.     Published on: 6th Jul 2005    |   Last Updated on: 22nd Jan 2009

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.

Ads

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.

Click here for Sample Code

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



 
This tutorial is part of a VB.NET 2005 tutorial series. Read it from the beginning and learn yourself.

VB.NET 2005

  1. VB.NET 2005 Free Training
  2. The .NET Framework Architecture Part 1
  3. The .NET Framework Architecture Part 2
  4. Application Class and Message Class
  5. Implementing Class Library Object
  6. Visual Studio.NET Namespaces
  7. .NET Assemblies
  8. Differences between VB.NET 1.0 and VB.NET 2.0
  9. Introducing VB.NET Windows Forms
  10. Visual Studio Windows Forms Designer
  11. Exploring the Forms Designer generated code
  12. Setting and Adding Properties to Windows Form
  13. Implementing Inheritance
  14. Event Handling In Visual Basic .NET
  15. Building Graphical Interface elements
  16. .NET Common Windows Forms Controls Part 1
  17. .NET Common Windows Forms Controls Part 2
  18. Common Controls and Handling Control Events
  19. DomainUpDown and NumericUpDown Controls
  20. Dialog Boxes in Visual Basic .NET
  21. Visual Studio Adding Controls to Windows Form
  22. VB.NET Validation Controls
  23. Working with Menu Controls
  24. VB.NET MDI Applications
  25. .NET Exceptions
  26. VB.NET Creating and Managing Components Part 1
  27. VB.NET Creating and Managing Components Part 2
  28. Simple Data Binding
  29. .NET Complex Data Binding
  30. .NET Data Form Wizard
  31. Data Manipulation with ADO.NET
  32. SQL Server Stored Procedures
  33. SQL Server Ad Hoc Queries
  34. Finding and Sorting Data in DataSets
  35. ADO.NET Object Model
  36. Working with DataSets
  37. Using XML Data
  38. Working with File System in .NET
  39. Creating Web Service
  40. Instantiating - Invoking Web Services, Creating Proxy Classes with WSDL
  41. Web Reference and Web Services
  42. Web Services - SOAP, WSDL, Disco and UDDI
  43. Web Application Testing in VB.NET 2005
  44. Web Application Tracing and Debugging
  45. Working with Legacy Code and COM Components
  46. ActiveX Controls and Legacy Code
  47. Windows Application Testing
  48. VB.NET Windows Application Testing
  49. Tracing VB.NET Windows Application
  50. Debugging Windows Applications In Visual Studio.NET 2005
  51. Deploying Windows Applications In Visual Studio.NET 2005
  52. Customizing Setup Project in Visual Studio.NET 2005
  53. Shared Assembly
  54. Microsoft .NET Creating Installation Components
  55. The Registry Editor in Visual Studio.NET 2005
  56. The File Types Editor
 

Comments