How to read a vb.net event in c#?

  • Thread starter Thread starter Frank Rizzo
  • Start date Start date
F

Frank Rizzo

Hello, I have a library written in vb.net that I want to use in my c#
project. The library has an event written as:

Public Event KeyPressed(ByVal Character As String, ByVal KeyCode As Integer)

I am trying to wire up this event in my c# class without success. I've
tried the following below, but obviously the method signature doesn't match:

keyboardHandler.KeyPressed += new System.EventHandler(this.HandleKeyPress);

Any ideas?
 
Uhm...

A couple of questions...

Why using or redefining an event that already exists (KeyPressed)?

I think your event definition is not quite correct cuz it looks to a
delegate to me ;-)

Public Event KeyPressed(ByVal Character As String, ByVal KeyCode As Integer)
' Event?! I don't think so...
Delegate Sub MyHandler(sender As Object, e As EventArgs) 'Delegate

My event definition would look like this...

Public Event MyEvent As MyHandler 'Event

In your code you have something like this...

keyboardHandler.KeyPressed += new System.EventHandler(this.HandleKeyPress);

You're using EventHandler Delegate and it doesn't match your event's
definition...

EventHandler Definition is like this...

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

it's totally different to yours...

Regards,
 
Angel said:
Uhm...

A couple of questions...
Why using or redefining an event that already exists (KeyPressed)?

This event ain't from a keyboard. I actually figured it out. The
framework creates all the right plumbing behind the scenes when you use
the classic VB syntax. So in C# you can call this as follows:

keyboardHandler.KeyPressed += new
Keyboard.KeyPressedEventHandler(this.HandleKeyPress);

No mucking with delegates is necessary.
Thanks
 
Back
Top