Click event of toolbar button is being fired twice: How to prevent it?

Posted on 2004-08-14
Last Modified: 2006-11-17
  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,
Question by:snehanshu
LVL 48

Expert Comment

ID: 11803041
Possibly there is some bug in your program. Please show your toolbar message handler.

On the other hand, once I worked with the mouse which gives double-click on every click. :-)

Author Comment

ID: 11803072
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).


Author Comment

ID: 11803090
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?
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

LVL 48

Expert Comment

ID: 11803204
I am using toolbars without problems. Event is fired only once.
LVL 10

Accepted Solution

ptmcomp earned 250 total points
ID: 11803776
Probably the event is registered twice. Search all your code (including hidden text). Make sure that the method that adds the event handler is only executed once.

Expert Comment

ID: 11805086
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.  

Author Comment

ID: 11807378
  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!!

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C# Offline Apllication 5 71
Server Error 11 58
C# Gridview 1 32
VB.NET 2008 Winforms Signing 13 19
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question