Technical Training
VB.NET 2005Table of Contents
Common Controls and Handling Control Events
Common Controls and Handling Control Events - Page 2Common Controls and Handling Control Events Page - 2
Common Controls and Handling Control Events
Handling Control Events
Controls are used as a primary medium of handling events. Rich set of events are specified for controls and their nature can be easily understood by reading their names. For example OnClick, MouseEnter, MouseLeave etc. describe the nature of the event they handle. Some of the events and their descriptions are given below:
|
Event Name
|
Description
|
|
BackColorChanged
|
Occurs when the BackClolor property of the control is changed
|
|
BindingContextChanged
|
Occurs when the BindingContext property of the control changes
|
|
ChangeUICues
|
Occurs when focus or keyboard cues changes
|
|
ContextMenuChanged
|
Occurs when the Contextmenu Property of the control is changed
|
|
KeyUp
|
Occurs when a key is released while the control has focus
|
|
Move
|
Occurs when the control is moved
|
|
Resize
|
Occurs when the control is resized
|
|
Paint
|
Occurs when the control is drawn or redrawn
|
|
LocationChanged
|
Occurs when the location property of the control changes
|
|
Validating
|
Occurs when the visible property of the control changes
|
All controls have been declared with the functionalities built into them and therefore are capable of executing the function when the user calls the event. This process is enabled by using the term “Handles”. The program that is executed will look like the one below.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
------------
------------
End Sub
The event handler takes two parameters in the above instance. The first is the sender as System.Object and the other is the valued ‘e’ as System.EventArgs. The Sender defines the object that has raised the event and the EventArg contains all the event specific data that the event sender passes.
There are other types of arguments that are accepted, such as FileSystemEventAtrgs, ImageClickEventArgs, KeyEventArgs and CommandEventArgs. Using the SenderObject could be particularly useful if a any action from out of a set of grouped actions is to be performed. Let us look at an example of this.
Start a new Visual Basic Windows Application Project in the Visual Studio IDE.
Add seven buttons and four labels and rename the buttons as shown as shown in the following screenshot.

Two labels label3 and label4 are not visible as the text is set to null. Now add the code as given below:
Click here for Sample Source Code
Here, we have used a CommonHandler that does some action based on the output of the various events. This is a simple code that changes the text of the labels. You can also write complex codes using loops that perform some action based on the event of the object that has sent the event. This facility is very useful in solving complex problems with simple solutions quickly.
In the next chapter we will learn about Common Dialog Boxes and Creating a Custom Dialog Box in Visual Studio .NET 2005 using Visual Basic.NET 2005.
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







