How can I know if a .net event is already handled?

前端 未结 8 2136

I\'ve written some code to handle an event as follows:

AddHandler myObject.myEvent, AddressOf myFunction

It seemed that everything was work

8条回答
  •  感情败类
    2020-12-31 10:05

    I know this is an old post but just wanted to add a solution for those who come looking in this direction...

    VB.Net creates a special private member variable in the pattern of Event that you can then use to test against Nothing.

    Public Event MyClick As EventHandler
    
    Private Sub OnMyClick()
        If MyClickEvent IsNot Nothing Then
            RaiseEvent MyClick(Me, New EventArgs())
        Else
            ' No event handler has been set.
            MsgBox("There is no event handler. That makes me sad.")
        End If
    End Sub
    

    Answer sourced from here: Determine if an event has been attached to yet

提交回复
热议问题