ButtonClick event happening twice when overriding method

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
 
G

Galcho[MCSD.NET]

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
 
M

Michael Moreno

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top