snehanshu
asked on
Click event of toolbar button is being fired twice: How to prevent it?
Hi!
I have written an application in C# .noe with Visual Studio 2003.
A problem that I am facing is that when I click a button, the event is being fired twice.
Has anybody else faced a similar problem? Does it happen for all events and always? How can I make the event to fire only once?
Looking forward to your help,
...Snehanshu
I have written an application in C# .noe with Visual Studio 2003.
A problem that I am facing is that when I click a button, the event is being fired twice.
Has anybody else faced a similar problem? Does it happen for all events and always? How can I make the event to fire only once?
Looking forward to your help,
...Snehanshu
ASKER
Ales,
I use a switch statement.
I check the indexof of the button in the event handler.
To fix this in a crude way, I have added a global counter variable that fires the event the first time and resets the counter the second time :-(
And this happens on all PCs where we run the app, so the mouse cannot be the problem.
I'll post the code when get to my office (perhaps tomorrow).
Thanks,
...Snehanshu
I use a switch statement.
I check the indexof of the button in the event handler.
To fix this in a crude way, I have added a global counter variable that fires the event the first time and resets the counter the second time :-(
And this happens on all PCs where we run the app, so the mouse cannot be the problem.
I'll post the code when get to my office (perhaps tomorrow).
Thanks,
...Snehanshu
ASKER
Sorry for the typo, Alex.
BTW, does C#, by any chance, fire events for both mouse down and mouse up as the same onclick event for toolbar buttons?
Can that be the problem?
...Shu
BTW, does C#, by any chance, fire events for both mouse down and mouse up as the same onclick event for toolbar buttons?
Can that be the problem?
...Shu
I am using toolbars without problems. Event is fired only once.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Can you post your code?
I assume you have traced it and your event handler is actually getting called twice. In which case,
did you register for the click event, or a mouse event? the mouse event will call mouse down and mouse up.
If you did register for the click event, then each registered method will only be fired once, but you may have adding you method twice. Check you code as ptm suggested if that is the case.
I assume you have traced it and your event handler is actually getting called twice. In which case,
did you register for the click event, or a mouse event? the mouse event will call mouse down and mouse up.
If you did register for the click event, then each registered method will only be fired once, but you may have adding you method twice. Check you code as ptm suggested if that is the case.
ASKER
ptmcomp,
You are the one!!
:-)
Yes, some how, the code for adding the event handler to the component appeared twice.
I commented one, and it works fine now!!
It would have been quite difficult to trace this down without your comment.
Thanks a lot!!
...Shu
You are the one!!
:-)
Yes, some how, the code for adding the event handler to the component appeared twice.
I commented one, and it works fine now!!
It would have been quite difficult to trace this down without your comment.
Thanks a lot!!
...Shu
On the other hand, once I worked with the mouse which gives double-click on every click. :-)