Solved

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

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

Expert Comment

by:AlexFM
Comment Utility
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. :-)
0
 
LVL 5

Author Comment

by:snehanshu
Comment Utility
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
0
 
LVL 5

Author Comment

by:snehanshu
Comment Utility
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
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 48

Expert Comment

by:AlexFM
Comment Utility
I am using toolbars without problems. Event is fired only once.
0
 
LVL 10

Accepted Solution

by:
ptmcomp earned 250 total points
Comment Utility
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.
0
 
LVL 5

Expert Comment

by:jjacksn
Comment Utility
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.  
0
 
LVL 5

Author Comment

by:snehanshu
Comment Utility
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
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now