Exforsys.com
 
Home Tutorials VB.NET 2005
 

VB.NET Creating and Managing Components Part 1

 

VB.NET Creating and Managing Components Part 1 - Page 2

Page 2 of 3


.


.


.



After adding the control to the ToolBox, you can also add three text boxes, two buttons and five labels and arrange them as you would see in the final output form shown below.


In the code editor add the following code to the Form1:


Click here for Sample Code


Now you can press F5 to execute the program. The output of the program is shown below:



Creating and implementing Events

In the example above validations for data entry have not been touched upon. In this section we shall see how validations can be added to the component. We shall assume a business rule that this calculator is used to calculate interest for Principal exceeding 100 for interest rate > 4 where the number of years is 2 or more.


For this purpose we shall create events. We shall also add programs to check the values and raise the events. The events that are raised will be handled in the windows application with the procedures that use the Handles keyword.


Events are declared using the keyword Event:


Event event name (Argument)


The event can be raised using the RaiseEvent keyword as shown below:


RaiseEvent event name


The modified code for the user control is given below:


Click here for Sample Code


The modified code for the windows application using this control is also shown below:


Click here for Sample Code


Now press F5 to execute the program. The following screenshots show us the way the three events are handled along with the normal termination of the program.


The error message


 


 


 


 


 


 


 


 


 


 


 


Extending a control through Visual Inheritance

The concept of Visual inheritance was introduced to facilitate the use and reuse of forms in VB.NET applications. It is Microsoft’s way of describing visual implementation of interfaces as objects. A base form is created and located in the class library project for use of multiple applications. When a form inherits from a base form, the controls on the base form appear in the derived form and cannot be modified if the modifier property of the base form has been set to Private or Friend. Therefore, if the derived form is to have the option of modifying the controls, the base form should have the control modifier properties set to Public or Protected.

The base form project will have to be compiled every time changes are made to the form. A change in one location will impact on all forms derived from the base form if the modifier property of the form is set to Private or Friend.

To derive a form object, the user has to simply add a new inherited form to his project. The inheritance picker will be launched and the user will be prompted to identify the base form. The application developer can choose the form available in the same assembly or can add another assembly and inherit a form from that assembly. In this case the developer will have all the display components of the parent form available to the newly added form.

Visual inheritance enables the programmers create user interfaces with ease. The capacity to inherit controls along with the form makes for rapid application development and generation of customized controls becomes easier.




Next Page: VB.NET Creating and Managing Components Part 1 - Page 3


Read Next: VB.NET Creating and Managing Components Part 2



 

 

Comments


abhineet komal said:

  This is nice , but plz do mention how to write the assembliles files, and call it with an example
December 30, 2008, 6:04 am

Sunil Yadav said:

  very nice but explain with more example
January 22, 2009, 3:48 am

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2009 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape