Exforsys.com
 
Home Tutorials VB.NET 2005
 

VB.NET Creating and Managing Components Part 2

 

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

Page 2 of 2

.

.


We have now added one property called ShadowColor and also have overridden the onTextChanged and onPaint methods.

Now we shall create a windows project in the Visual Studio. Right-click on the ToolBox to and click on “Choose Items ..”. A new dialog box to add control is shown. Navigate to the custom control that we have created and add the control. The control will be displayed in the ToolBox. We can now drag and drop this control on the Form. Now click F5 to see the result. The onTextChanged method and onPaint event which have been overridden have caused the visual effect to happen as shown by the screenshot below:


.


..


Creating components by extending the Component class

Component classes are inherited from System.ComponentModel.Component. By inheriting from this class, the application developer is provided with a good designer surface, like that of Forms designer. This designer is called component designer. Controls can be dragged and dropped on to this designer from the tools box.

This helps the developer build quicker and easier solutions. Server controls can be added rapidly to the solution. Let us now take a look how easily this can be done.


The application developer can Drag and drop any component to the class from the ToolBox and extend the facility or he can open the code view and author a new component altogether.

Click on the code view. Now add the following lines of code to the class:


Click here for Sample Code


The instance initialization parameters are shown in the member variables. Only InstanceID is declared as public.

One property is defined to return the value of ClassInstanceCount. The Finalize method is overridden to decrement the value of ClassInstanceCount. Now the developer can build the solution to make it available for the being consumed. This can be imported to the toolbox and used by dragging and dropping.



To consume this component, create a windows application project in visual studio. Add reference to the component’s namespace. Add a button control and a timer component to the form. Enter the following code to the Form1.

Click here for Sample Code

In this example we are entering code to the timer’s Tick Event handler that shows the instance count as the forms caption. We are also adding the codes to the button’s click Event handler that instantiates the component 1000 times. Now we locate the sub new and add the following code to start the timer immediately after initialization of the component.


Click here for Sample Code


Now press F 5 to execute the program. The output is shown below:


The Screen shot at start up showing the instance number


The screen shot after pressing the button







First Page: VB.NET Creating and Managing Components Part 2


Read Next: .NET Assemblies



 

 

Comments


Ken said:

  While the article addresses many components - I find some things are lacking - such as creating html components with no closing end tag such as
these are not created with the generic control - so how do you build them ??
May 7, 2008, 12:41 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