我想设置一个回调,该回调将由另一个班级在我的班级中引发:
Public Class CameraWindow
Inherits System.Windows.Forms.Control
Private m_camera As Camera = Nothing
' Camera property
<Browsable(False)> _
Public Property Camera() As Camera
Get
Return m_camera
End Get
Set(value As Camera)
' lock
Monitor.Enter(Me)
' detach event
If m_camera IsNot Nothing Then
m_camera.NewFrame -= New EventHandler(AddressOf camera_NewFrame)
timer.[Stop]()
End If
m_camera = value
needSizeUpdate = True
firstFrame = True
flash = 0
' atach event
If m_camera IsNot Nothing Then
m_camera.NewFrame += New EventHandler(AddressOf camera_NewFrame)
timer.Start()
End If
' unlock
Monitor.[Exit](Me)
End Set
End Property
' On new frame ready
Private Sub camera_NewFrame(sender As Object, e As System.EventArgs)
Invalidate()
End Sub
事件定义在
Public Class Camera
Public Event NewFrame As EventHandler
但是 VB.NET 不喜欢我附加和分离事件的方式。有人可以告诉我如何正确地做到这一点吗?
非常感谢你的帮助!