An interface can declare an event. The following example shows how to implement interface events in a class. Basically the rules are the same as when implementing any interface method or property.
To implement interface events in a class
-
Declare the event in your class and then invoke it in the appropriate places
-
public interface IDrawingObject { event EventHandler ShapeChanged; } public class MyEventArgs : EventArgs {…} public class Shape : IDrawingObject { event EventHandler ShapeChanged; void ChangeShape() { // Do something before the event… OnShapeChanged(new MyEventsArgs(…)); // or do something after the event. } protected virtual void OnShapeChanged(MyEventArgs e) { if(ShapeChanged != null) { ShapeChanged(this, e); } } }