Technical Training
VB.NET 2005Table of Contents
VB.NET Creating and Managing Components Part 2
VB.NET Creating and Managing Components Part 2 - Page 2VB.NET Creating and Managing Components Part 2 Page - 2
VB.NET Creating and Managing Components Part 2
.
.
Ads
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:
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.
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 |
|
|
|
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









