简体   繁体   English

C#转VB.net转换错误

[英]C# to VB.net convertion error

I am trying to use MIDI.NET in Visual Basic 2010 while it is written in C#. 我试图在Visual Basic 2010中使用MIDI.NET,而它是用C#编写的。 So I got the tip to convert it using an online converter since these languages are quitte similair to eachother. 所以我得到了一个使用在线转换器转换它的提示,因为这些语言是相互同步的。 The one problem I have is this line 我遇到的一个问题是这一行

inputDevice.NoteOn += new InputDevice.NoteOnHandler(NoteOn);

converted to vb.net it looks like this 转换为vb.net它看起来像这样

InputDevice.NoteOn += New InputDevice.NoteOnHandler(NoteOn)

which gives me 2 errors. 这给了我2个错误。

  1. 'Public Event NoteOn(msg As NoteOnMessage)' is an event, and cannot be called directly. 'Public Event NoteOn(msg As NoteOnMessage)'是一个事件,不能直接调用。 Use a 'RaiseEvent' statement to raise an event. 使用'RaiseEvent'语句来引发事件。 C:\\Users\\Den Houting\\AppData\\Local\\Temporary Projects\\MIDI\\Form1.vb 14 9 MIDI C:\\ Users \\ Den Houting \\ AppData \\ Local \\ Temporary Projects \\ MIDI \\ Form1.vb 14 9 MIDI

  2. Error 3 Delegate 'Midi.InputDevice.NoteOnHandler' requires an 'AddressOf' expression or lambda expression as the only argument to its constructor. 错误3委托'Midi.InputDevice.NoteOnHandler'需要'AddressOf'表达式或lambda表达式作为其构造函数的唯一参数。 C:\\Users\\Den Houting\\AppData\\Local\\Temporary Projects\\MIDI\\Form1.vb 14 82 MIDI C:\\ Users \\ Den Houting \\ AppData \\ Local \\ Temporary Projects \\ MIDI \\ Form1.vb 14 82 MIDI

When trying to do something like RaiseEvent NoteOn it tells me NoteOn isn't an event. 当试图做像RaiseEvent NoteOn这样的事情时,它告诉我NoteOn不是一个事件。

Thanks. 谢谢。

The proper syntax in VB.NET uses AddHandler to register the event VB.NET中的正确语法使用AddHandler来注册事件

AddHandler InputDevice.NoteOn, AddressOf NoteOn

More on MSDN . 更多关于MSDN

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM