Event Handling

• Event: An event is a run time action, that can be performed by the user.
• Ex: Click, DoubleClick, MouseMove, KeyPress etc.
• Then event handling includes with executing some code, whenever the user performs an event.
• The necessary code is to be written in a special method. That method is called as “Event Handler”.

Event Handler:
• An event handler is a method, that gets executed automatically, whenever the user performs certain event at run time.
• The event handler should be defined in the form class.

Syntax
private void controlname_eventname(object sender, EventArgs e)
{
--------------;
--------------;
--------------;
}
Event handling
Implementation of Event Handler:
• First, select the form or control, for which you want to create the event handler.
• Open “Properties” window, and click on “Events” option.
• Select the required event, for which you want to create the event handler.
• Press Enter.
• Then the event handler will be created in the code window.

Demo on Event Handling

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace EventHandlingDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Click(object sender, EventArgs e)
{
MessageBox.Show("This is Click Event...");
}
}
}
Event handling