0

i am Handling Event in vb.net

 AddHandler ButtonOne.Click, AddressOf ButtonClick

 Private Sub ButtonClick(ByVal ctrl As Office.CommandBarButton, ByRef Cancel As Boolean)
    //do stuff
 End sub

But my event calling twice.when i click onces on button and in another method also i am handling same event

   Private Sub AddToolbar()
   // do something
     AddHandler firstButton.Click, AddressOf ButtonClick
   End 

How to resovle this issue ? plz help me

Dolphin
  • 138
  • 1
  • 3
  • 16
  • 2
    You just called AddHandler for the same button's Click event twice. Delete one of them. – Hans Passant Mar 05 '14 at 10:40
  • ButtonOne.Click and firstButton.Click are two different buttons – Dolphin Mar 05 '14 at 12:19
  • That's not what your complaint suggests. "One" and "first" are suspiciously similar of course. Picking good identifier names and avoiding storing a reference to an object in multiple variables are good ways to stay out of trouble. – Hans Passant Mar 05 '14 at 12:40

1 Answers1

4

As Hans pointed out.... you are calling the button click twice... Also see below

AddHandler ButtonOne.Click, AddressOf ButtonClick 'You dont really need this if you add a handler to the sub see below...

 Private Sub ButtonClick(ByVal ctrl As Office.CommandBarButton, ByRef Cancel As Boolean) Handles ButtonOne.Click
    //do stuff
 End sub
Mych
  • 2,527
  • 4
  • 36
  • 65