How can we use the "sender" parameter of a button-click event?

Add-in Express™ Support Service
That's what is more important than anything else

How can we use the "sender" parameter of a button-click event?
 
Leon Lai Kan




Posts: 200
Joined: 2018-12-20
I have already sorted out the problem

Hello,

I always wondered what we can do with the sender parameter of a click event.

So, it was a nice surprise when I found a simple example on the web.

Here is the code:

Private Sub Button_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
                                  Handles Button1.Click, Button2.Click

   Dim s As String
   If sender Is Button1 Then
      s = "button1"
   ElseIf sender Is Button2 Then
      s = "button2"
   End If

   MessageBox.Show("You pressed: " & s)
End Sub


I created 2 buttons in the Ribbon: Button1, and Button2

Then I copied the above code in AddInModule.vb.

As expected, it will not work.

I get this Error Message:

Method 'Private Sub Button_Click(sender As Object, e As System.EventArgs)'
cannot handle event
'Public Event OnClick(sender As Object, control As AddinExpress.MSO.IRibbonControl, pressed As Boolean)'
because they do not have a compatible signature.


Can you help me make the sample work (if this is possible)?


Thanks
Leon


added:

I modified the 1st line to:

Private Sub Button_OnClick(ByVal sender As System.Object, _
ByVal control As AddinExpress.MSO.IRibbonControl, _
ByVal pressed As System.Boolean) Handles Button1X.OnClick, Button2X.OnClick


This time no build error, but does not work

ADDED

It now works.
I has commented out the MessageBox line and forgot to uncomment.
No need to reply
Best Regards
Leon
Posted 25 Apr, 2019 07:42:17 Top
Andrei Smolin


Add-in Express team


Posts: 17115
Joined: 2006-05-11
Hello Leon,

Thank you for letting us know!

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 25 Apr, 2019 08:14:31 Top