VB.NET Event addressof -
i set callback raised in class different class:
public class camerawindow inherits system.windows.forms.control private m_camera camera = nothing ' camera property <browsable(false)> _ public property camera() camera return m_camera end set(value camera) ' lock monitor.enter(me) ' detach event if m_camera isnot nothing 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 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 object, e system.eventargs) invalidate() end sub
the event defined in
public class camera public event newframe eventhandler
but vb.net not way attach , detach events. can tell me how correctly?
thank help!
that looks if you're using c#. in vb.net use addhandler
statement:
addhandler m_camera.newframe, addressof camera_newframe
to remove handler use removehandler
removehandler m_camera.newframe, addressof camera_newframe
however, if event handler in different class need public:
public sub camera_newframe(sender object, e system.eventargs) invalidate() end sub
and need instance:
addhandler camera.newframe, addressof m_camera.camera_newframe
Comments
Post a Comment