Method '<method>' cannot handle Event '<event>' because...

I am getting the following error where ntfHelpDesk is a NotifyIcon.

<color="firebrick">Method 'ntfHelpDesk_DoubleClick' cannot handle Event 'DoubleClick' because they do not have the same signature.</color>

Any help is appreciated.

[261 byte] By [codefund.com] at [2007-12-16]
# 1
Please pardon me if this question is really stupid, but I figure it's worth asking the obvious: does your event handler have the correct signature? To verify, I just created a NotifyIcon with a DoubleClick event handler, and it worked fine.

The event handler you assign to the DoubleClick event must be a standard EventHandler delegate, like this:

Public Delegate Sub EventHandler( _
ByVal sender As Object, _
ByVal e As EventArgs _
)

That is, your event handler must accept two parameters of these exact types, and must return no value (or return void, in C#). Did you check to make sure your event handler meets these requirements?

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2
Ken,

I mentioned before that I am usually an ASP.Net guy. So maybe that's problem #1 :)

Anyway, here is my sub that is giving me that error:Private Sub ntfHelpDesk_DoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ntfHelpDesk.DoubleClick
System.Diagnostics.Process.Start("C:\Program Files\Internet Explorer\IEXPLORE.EXE","http://www.msn.com")
End SubDo you think you can help?

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 3
<b>Nevermind, I fixed it!</b>

Here is what my code ended up looking like:Private Sub ntfHelpDesk_DoubleClick (ByVal sender As Object, ByVal e As System.EventArgs) Handles ntfHelpDesk.DoubleClick
System.Diagnostics.Process.Start("C:\Program Files\Internet Explorer\IEXPLORE.EXE","http://www.msn.com")
End Sub
Thanks for all the help!

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 4
Well, the issue has nothing to do with WinForms vs. Web Forms. It's just a .NET issue.

The DoubleClick event for a NotifyIcon control uses the EventHandler delegate, which only accepts an EventArgs object in its second parameter. You're passing a MouseEventArgs parameter, so the code won't compile. You'd think that if the parameter inherited from the base class, it would work, but that's not the way delegates work in .NET. Therefore, to get this to work, your code will have to match the EventHandler delegate exactly, and look like this:

Private Sub ntfHelpDesk_DoubleClick(ByVal sender As System.Object, ByVal e As EventArgs) Handles ntfHelpDesk.DoubleClick
System.Diagnostics.Process.Start("C:\Program Files\Internet Explorer\IEXPLORE.EXE","http://www.msn.com")
End Sub

That should make it at least compile (I can't vouch for your paths and all that, but the code should at least COMPILE now <g>.

Your best bet, if you're just getting started coding with Windows Forms, is to allow Visual Studio .NET to create the event handlers for you. That way, you're guaranteed that they provide the correct parameter signature!

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 5
Talk about posts crossing. Very funny. While I was typing a response, you were typing yourself a response! Glad you got it worked out.
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 6
btw, unless you want to force your user to only use IE, you can just do this to open a browser, no matter what browser they're using...

System.Diagnostics.Process.Start(" http://www.msn.com")

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 7
Ken,

Thanks for the response. I remembered how to get the proper properties by using the drop-down boxes in VS.Net.

Erik,

Thanks for the pointer. I have a config file that I read in their exact browser location unless they have more than one, and prefer to open this particular site in a specific browser. I just through in the path as example

;)

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 8
Just for the record, the compiler will also complain when the signatures differ in the way of passing the parameters (ByVal vs ByRef). Strange enough as complex objects are always passed byRef (so I was told)

H

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 9
Good point. I should have double-checked that. Never trust automatic coding! ;)
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 10
actually, I believe the default is ByVal for everything. Intellisense in VB.NET fills in ByVal for you unless you specify ByRef specifically and C# just never has anything, unless it's ref. If ByRef were the default, then anytime you change a property in the object coming in, the original that was passed in would be changed as well (since it would just be a direct reference).
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 11
It's important to remember that the default in VB6 was to pass everything by reference, unless you included the ByVal keyword. So the default changed in .NET, and this can be confusing for folks that never really got the difference to begin with (and believe me, after teaching VB6 classes for years, most folks don't).
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 12
I see...gotchya Ken. Quite honestly, I used VB6 for a few years and never new that was the default! :-|
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 13
That is a great pointer Ken! Thanks for that info. I used VB6 primarily for small apps. Now that I'm moving from ASP.Net to Windows Apps, I'm learning a ton!
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 14
<quote>
Now that I'm moving from ASP.Net to Windows Apps
</quote>

woohoo...way to be! :)

I did the same thing about 6-9 months ago...I originally started on just ASP.NET, but now, I'm about 85% WindowsForms and 15% WebForms :|

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...