VB.NET类实现事件

时间:2014-03-06 13:00:15

标签: c# vb.net events interface

我看不出我做错了什么。

IDE告诉我

 "Class 'CaptureDevice' needs to implement event 'Event NewFrame(sender As Object, e As CameraEventArgs) for 'IVideoSource'.

“CaptureDevice”类看起来像这样:

Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.IO
Imports System.Threading
Imports System.Runtime.InteropServices
Imports System.Net
Imports dshow
Imports dshow.Core

Namespace VideoSource

    Public Class CaptureDevice
        Implements IVideoSource
        Private source As String
        Private m_userData As Object = Nothing
        Private m_framesReceived As Integer

        Private thread As Thread = Nothing
        Private stopEvent As ManualResetEvent = Nothing

        ' new frame event '
        Public Event NewFrame As CameraEventHandler

        '(...)'
    End Class
End Namespace

我的班级'IVideoSource'看起来像这样:

Namespace VideoSource

    'IVideoSource interface'
    Public Interface IVideoSource

        Event NewFrame As CameraEventHandler

    End Interface

End Namespace

有人看到我出错的地方或可能遗失的地方吗?

非常感谢您的帮助!

2 个答案:

答案 0 :(得分:1)

CaptureDevice课程中,请改为:

Public Event NewFrame As CameraEventHandler Implements IVideoSource.NewFrame

虽然C#假定一个实现接口成员名称相同的公共成员作为实现,但VB.NET要求实现明确声明。

答案 1 :(得分:1)

您需要添加Implements子句,例如:

Public Event NewFrame As CameraEventHandler Implements IVideoSource.NewFrame

VB.Net没有c#的隐式接口实现。