提问人:roy 提问时间:10/12/2022 更新时间:10/12/2022 访问量:188
未为 VB.NET 中的参数指定参数
Argument not specified for parameter in 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:\Users\Admin\documents\visual studio 2012\Projects\Barcode Scanner using Webcam in VB.NET\Barcode Scanner using Webcam in VB.NET\Form1.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:\Users\Admin\documents\visual studio 2012\Projects\Barcode Scanner using Webcam in VB.NET\Barcode Scanner using Webcam in VB.NET\Form1.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:\Users\Admin\documents\visual studio 2012\Projects\Barcode Scanner using Webcam in VB.NET\Barcode Scanner using Webcam in VB.NET\Form1.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;
}
答:
1赞
jmcilhinney
10/12/2022
#1
这不是在 VB 中注册事件处理程序的方式。这:
videoCaptureDevice.NewFrame += VideoCaptureDevice_NewFrame
应该是这样的:
AddHandler videoCaptureDevice.NewFrame, AddressOf VideoCaptureDevice_NewFrame
评论
0赞
roy
10/12/2022
感谢您的回答没有错误
评论
Option Strict On