Handling a buttons Event in C#

This is 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.


Attachments

  • Code with windows form (30510-16232-Events.zip)
  • Comments

    No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: