Saturday 7 May 2011

Custom Event In The Custom Control

It is good rule to add Custom Events in the Custom Controls you build. It allows easy to use your control from the external code without any problems.

How to add Custom Event? Very easy, just add this code to your class:


// delegate declaration

public delegate void ChangingHandler(object sender);

// event declaration

public event ChangingHandler OnDoFilter;

// this one is to call event

private
void FireOnDoFilter(object sender)
{
  if (OnDoFilter != null)
  {
    OnDoFilter(sender);
  }
}


Custom Events are easy to create and easy to use. Lets use it!

Hope this helps!

No comments:

Post a Comment

Note: only a member of this blog may post a comment.