I’m making a custom button (Winforms Control Library) and have the code below so that all mouseenter will be added to all controls in my button. When I run it, it causes a stack overflow exception. I have the same code with Click instead of MouseEnter and it works fine. Here is the code:
public new event EventHandler MouseEnter {
add
{
this.MouseEnter += value;
foreach (Control i in Controls)
{
i.MouseEnter += value;
}
}
remove
{
this.MouseEnter -= value;
foreach (Control i in Controls)
{
i.MouseEnter -= value;
}
}
}
here is the click code:
public new event EventHandler Click {
add {
this.Click += value;
foreach (Control i in Controls) {
i.Click += value;
}
}
remove {
this.Click -= value;
foreach (Control i in Controls) {
i.Click -= value;
}
}
}
I ended up replaceing this.Click with base.Click.