ButtonClick event happening twice when overriding method

  • Thread starter Thread starter Michael Moreno
  • Start date Start date
M

Michael Moreno

Hello,

In a Base Form I have a toolbar and have implemented the Click event
as:

protected virtual void toolBar1_ButtonClick(object sender,
System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
if (e.Button == tbClose)
Close();
}

In inherited Forms I add other buttons to the toolbar and assign the
Click event and write things like:

protected override void toolBar1_ButtonClick(object sender,
System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
if (e.Button == tbCalc)
Calc();
else
base.toolBar1_ButtonClick(sender, e);
}

The problem is that when I click on the tbCalc button the event is
raised twice and that I will end up calling twice the Calc() method.

Would anybody understand why please?

Thanks,
Michael
 
this is because you have two event handlers attached to same event

see in designer code if you have code for attaching events

hope this helps
Galin Iliev[MCSD.NET]
www.galcho.com
 
this is because you have two event handlers attached to same event
see in designer code if you have code for attaching events

Yes that was it!
I would have never found out alone!
Thanks
 
Back
Top