How do I Implement Custom Event Handling in C#
By October 27, 2005
In this article, we are going to show, how we can call custom event on our designed conditions.
Tne following source code shows how to implement custom event handling in C#.
using System;
class CustomEventBinding
{
public CustomEventBinding()
{
CustomEventHandling.operationEvent += new OperationEventHandler(ShowStatus);
SendNumber();
}
private void SendNumber()
{
CustomEventHandling customEventHandle = new CustomEventHandling();
customEventHandle.CheckNumber(8);
customEventHandle.CheckNumber(9);
}
private void ShowStatus(string message)
{
Console.WriteLine(message);
}
}
class CustomEventHandling
{
public delegate void OpeartionEventHandler(string message);
public static event OperationEventHandler operationEvent;
int i = 0;
//Indicate whether given number is even or odd
public void CheckNumber(int number)
{
int rem = number % 2;
if(rem == 0)
operationEvent("Even Number");
else
operationEvent("Odd Number");
}
}
From:
http://www.c-sharpcorner.com/UploadFile/Ashish1/customeevents10272005221603PM/customeevents.aspx?ArticleID=a509d6c1-205a-4944-ad31-1743ec87c0e3