alt
Advertisement
Online Training
Career Series
Exforsys
Exforsys arrow Tutorials arrow VB.NET 2005 arrow Common Controls and Handling Control Events
Site Search


Common Controls and Handling Control Events
Article Index
Common Controls and Handling Control Events
Page 2

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.


Trackback(0)
Comments (0)add comment

Write comment

busy

 
< Prev   Next >
Sponsored Links
© 2008 Exforsys.com
Joomla! is Free Software released under the GNU/GPL License.
Page copy protected against web site content infringement by Copyscape