0

I have a WinForms user control when I have hidden Control.Click using

public new event EventHandler Click
{
    add
    {
        base.Click += value;
        foreach (Control control in Controls)
        {
            control.Click += value;
        }
    }
    ...
}

(see this question). This works well and all is fine and dandy, until I cast it to a generic Control (for example when passing a reference to something that knows nothing about the specific user control type).

In this case, when adding a click handler it is bound to the base Control_Click, completely bypassing the above method that was supposed to hide the base method. Any suggestions?

Community
  • 1
  • 1
D Conroy
  • 1
  • 1
  • 1
    Such are the hazards of using the *new* keyword to suppress that strongly-worded compiler warning. Just don't do this, there is no point in micro-optimizing code that runs at human-time. Iterate the controls in the constructor and subscribe their Click events, have the event handler call OnClick(). – Hans Passant Sep 17 '15 at 17:01
  • Thank you Hans. Sometimes, after using the _generic/lazy_ way it is easy to miss the blindingly obvious. At least for me. – D Conroy Sep 17 '15 at 19:19

0 Answers0