Posted By

maxbaines on 08/04/10


Tagged

events


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

merwan
Vordreller
sjdjones
rageit
jimfred
Tyster


Event Handler


 / Published in: C#
 

  1. class EventSender
  2. {
  3. public delegate void testEventHandler(object sender, EventArgs e);
  4.  
  5. public event testEventHandler testEvent;
  6.  
  7. public void makeEvent()
  8. {
  9. // Trigger event
  10. testEvent(this, new EventArgs());
  11. }
  12. }
  13.  
  14.  
  15. class EventReceiver
  16. {
  17. EventSender eventSender;
  18.  
  19. private void registerEvent()
  20. {
  21. eventSender.testEvent += new EventSender.testEventHandler(testEventHandler);
  22. }
  23.  
  24. private void testEventHandler(object sender, EventArgs e)
  25. {
  26. // Event is handled here
  27. }
  28. }

Report this snippet  

You need to login to post a comment.