The custom event arguments with a cancel property
Public Class MyEventArgs
Inherits EventArgs
Private CancelValue As Boolean = False
Sub New()
MyBase.New()
End Sub
Public Property Cancel As Boolean
Get
Return CancelValue
End Get
Set(value As Boolean)
CancelValue = value
End Set
End Property
End Class
When you use the event in the class that raises the event you can raise the event and wait before you execute code. example:
Public Class MyObject
Public Event MyEvent(e As MyEventArgs)
Public Sub MySub()
Dim MyEvent1 As New MyEventArgs()
RaiseEvent MyEvent(MyEvent1)
If MyEvent.Cancel = False Then
'Do the thing
Else
'Don't do the thing
End If
End Sub
End Class
When the event gets raised by the object simply set e.cancel = True like the following:
Private Sub MyObject1_MyEvent(e As MyEventArgs) Handles MyObject1.MyEvent
If SomethingHappens Then
e.cancel = True
End If
End Sub