未为VB.NET中的参数指定参数



尊敬的所有程序员

我尝试在vb.net中的项目中出现错误,但如果我在c#项目中运行它,则没有错误。我的vb.net代码有问题吗?。有没有其他解决方案可以使vb.net项目中没有错误?

感谢

'this is the result of an error from project vb.net
Error   3   Argument not specified for parameter 'sender' of 'Private Sub VideoCaptureDevice_NewFrame(sender As Object, eventArgs As AForge.Video.NewFrameEventArgs)'.  C:UsersAdmindocumentsvisual studio 2012ProjectsBarcode Scanner using Webcam in VB.NETBarcode Scanner using Webcam in VB.NETForm1.vb 16  40  Barcode Scanner using Webcam in VB.NET
Error   2   Argument not specified for parameter 'eventArgs' of 'Private Sub VideoCaptureDevice_NewFrame(sender As Object, eventArgs As AForge.Video.NewFrameEventArgs)'.   C:UsersAdmindocumentsvisual studio 2012ProjectsBarcode Scanner using Webcam in VB.NETBarcode Scanner using Webcam in VB.NETForm1.vb 16  40  Barcode Scanner using Webcam in VB.NET
Error   1   'Public Event NewFrame(sender As Object, eventArgs As AForge.Video.NewFrameEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.  C:UsersAdmindocumentsvisual studio 2012ProjectsBarcode Scanner using Webcam in VB.NETBarcode Scanner using Webcam in VB.NETForm1.vb 16  9   Barcode Scanner using Webcam in VB.NET
'Code in VB.NET
Private Sub btnStart_Click_1(sender As Object, e As EventArgs) Handles btnStart.Click
videoCaptureDevice = New VideoCaptureDevice(filterInfoCollection(cboCamera.SelectedIndex).MonikerString)
'the line of code below error
videoCaptureDevice.NewFrame += VideoCaptureDevice_NewFrame
videoCaptureDevice.Start()
End Sub
Private Sub VideoCaptureDevice_NewFrame(ByVal sender As Object, ByVal eventArgs As AForge.Video.NewFrameEventArgs)
Dim bitmap As Bitmap = DirectCast(eventArgs.Frame.Clone(), Bitmap)
Dim reader As New BarcodeReader()
Dim result = reader.Decode(bitmap)
If result IsNot Nothing Then
txtBarcode.Invoke(New MethodInvoker(Sub()
txtBarcode.Text = result.ToString()
End Sub))
End If
pictureBox.Image = bitmap
End Sub
'Code in C#
private void btnStart_Click(object sender, EventArgs e)
{
videoCaptureDevice = new VideoCaptureDevice(filterInfoCollection[cboCamera.SelectedIndex].MonikerString);
videoCaptureDevice.NewFrame += VideoCaptureDevice_NewFrame;
videoCaptureDevice.Start();
}
private void VideoCaptureDevice_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
{
Bitmap bitmap = (Bitmap)eventArgs.Frame.Clone();
BarcodeReader reader = new BarcodeReader();
var result = reader.Decode(bitmap);
if (result != null)
{
txtBarcode.Invoke(new MethodInvoker(delegate()
{
txtBarcode.Text = result.ToString();
}));
}
pictureBox.Image = bitmap;
}

这不是在VB中注册事件处理程序的方式

videoCaptureDevice.NewFrame += VideoCaptureDevice_NewFrame

应该是这样的:

AddHandler videoCaptureDevice.NewFrame, AddressOf VideoCaptureDevice_NewFrame

最新更新