ARTICLE

How do I Implement Custom Event Handling in C#

Posted by Ashish Singhal Articles | How do I October 27, 2005
In this article, we are going to show, how we can call custom event on our designed conditions.
Reader Level:

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");
}
}

Login to add your contents and source code to this article
post comment
     
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter