Check The Following Code Snippet
Create a windows form application using C#. It shows how to handle an event of a button. It uses events like mouse enter, mouse leave, Click, etc..
There is a form with a button and a label which shows the event we are dealing with.
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 WindowsFormsApplication1
{
public partial class Events : Form
{
public Events()
{
InitializeComponent();
}
private void btnEvents_Click(object sender, EventArgs e)
{
lblEvents.Text = "Button is clicked";
}
private void btnEvents_Enter(object sender, EventArgs e)
{
lblEvents.Text = "Button is Active";
}
private void btnEvents_Leave(object sender, EventArgs e)
{
lblEvents.Text = "Button is Inactive";
}
private void btnEvents_MouseEnter(object sender, EventArgs e)
{
lblEvents.Text = "Mouse is on button";
}
private void btnEvents_MouseLeave(object sender, EventArgs e)
{
lblEvents.Text = "Mouse is on form";
}
private void Events_Resize(object sender, EventArgs e)
{
lblEvents.Text = "resizing the form";
}
}
}
I have attached the code you can also download it.