2014-03-06 64 views
0

我不明白我做錯了什麼。VB.NET類實現事件

的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 

有誰看到我錯了什麼地方或者可能錯過了什麼?

非常感謝您的幫助!

+0

你有另一個事件在你的接口中聲明'Event NewFrame(sender As Object,e As CameraEventArgs)'嗎? –

+0

'VideoSource'命名空間中還有'CameraEventHandler'嗎? – Crono

+0

這將有助於閱讀:http://msdn.microsoft.com/en-us/library/cd43d244.aspx –

回答

1

您需要添加Implements條款,所以,這樣的:

Public Event NewFrame As CameraEventHandler Implements IVideoSource.NewFrame 

VB.Net沒有C#的隱式接口的實現。

+0

這是行不通的。 IDE告訴我「接口中的事件可能不會被聲明爲'Implements' – tmighty

+0

@tmighty這是不對的,你確定你是用同樣的方式聲明事件嗎? – Crono

+0

@tmighty - 聽起來像你'重新嘗試將'Implements'應用於接口定義,這是錯誤的,你將它應用於'CaptureDevice'中的'Event'。 –

1

在你CaptureDevice類,而是執行此操作:

Public Event NewFrame As CameraEventHandler Implements IVideoSource.NewFrame 

雖然C#假設有實現的接口的成員是執行的相同名稱的公共成員,VB.NET要求實現被明確地聲明。