Ross Coded Classes

Programming tips with no rose colored glasses.

Event Properties

Don’t forget about event properties.

Sometimes an interface requires an event that really is the same as an existing event.  This can be accomplished by forwarding the new to the existing event. 

There is nothing wrong with this version:

public event EventHandler ValueChanged;

protected override void OnCheckedValueChanged()
{
      base.OnCheckedValueChanged();

      EventHandler handler = ValueChanged;
      if handler != null)
      {
            handler(this, EventArgs.Empty);
      }
}

This does the same thing and I think this version is cleaner:

public event EventHandler ValueChanged
{
      add { CheckedChanged += value; }
      remove { CheckedChanged -= value; }
}