Windows Forms Event Handler in VB.NET

In this article you will learn how to work with event handler in Windows Forms.
  • 2027

An Event is generated when a user performs an action, such as clicking the mouse or pressing a key. When a user clicks a form, the Click event is generated for the form. Each form and control has a predefined set of events associated with it. You can specify the action to be performed on the occurrence of an event within a special method called event handler. You can add code for an event handler by using the Code Editor window. Let us see how to work with an event handler.

Create a new form and drag a button on it. 

1.gif
 
Open the properties window for the button and click the Event button(  ) on the toolbar in the properties window. The following figure shows the list of events for the button control:  

2.gif
 
When you double click on any event in this list, for example KeyDown, the declaration for the event handler is automatically provided in the Code Editor window, as shown in the following figure: 

3.gif
 
You can type code within the event handler. When an event is raised, code in the corresponding event handler is executed.
The following code shows an event handler for the Load event of Form1:
private void Form1_Load(object sender, EventArgs e)
{
}

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.