Home All Groups Group Topic Archive Search About

Method does not have same signature etc...

Author
29 Oct 2006 1:28 PM
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,


Author
29 Oct 2006 8:00 PM
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

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.