Guest User

Untitled

a guest
Apr 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. namespace EventsPractice
  2. {
  3. class Program
  4. {
  5. static void Main(string[] args)
  6. {
  7. Point point = new Point();
  8.  
  9. point.PointChanged += HandlePointChanged;
  10. }
  11.  
  12. }
  13. class Point
  14. {
  15. private double x;
  16. private double y;
  17.  
  18. public double X
  19. {
  20. get { return x; }
  21. set
  22. {
  23. x = value;
  24. OnPointChanged();
  25. }
  26. }
  27. public double Y
  28. {
  29. get { return y; }
  30. set
  31. {
  32. y = value;
  33. OnPointChanged();
  34. }
  35.  
  36. }
  37.  
  38. public event EventHandler PointChanged;
  39.  
  40. public void OnPointChanged()
  41. {
  42. if (PointChanged != null)
  43. PointChanged(this, EventArgs.Empty);
  44. }
  45.  
  46. public void HandlePointChanged(object sender, EventArgs eventArgs)
  47. {
  48. // Do something Here
  49. }
  50.  
  51. }
  52. }
  53.  
  54. point.PointChanged += HandlePointChanged;
Add Comment
Please, Sign In to add comment