Method does not have same signature etc...

A

Anil Gupte

I created a button dynamically and added an event hander as follows:
AddHandler newbtnPick.Click, AddressOf newbtnPick_Click

Private Sub newbtnPick_Click()

End Sub

I get an error:
Method 'Public Sub newbtnPick_Click()' does not have the same signature as
delegate 'Delegate Sub EventHandler(sender As Object, e As
System.EventArgs)'.

So of coutse I added
ByVal sender As Object, ByVal e As EventArgs

to give me
Private Sub newbtnPick_Click(ByVal sender As Object, ByVal e As EventArgs)

End Sub

In fact even this does nto work:
Private Sub newbtnPick_Click(ByVal sender As Object)

End Sub

Why do I need the second parameter? And I am curious, how does it know I
will need the sender object?

Thanx,
 
M

Mattias Sjögren

Why do I need the second parameter? And I am curious, how does it know I
will need the sender object?

You need to make sure the method signature matches the delegate
signature. It doesn't matter if you're actually going to use the
parameters in your code or not.


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top