IN VB.NET (not c#)...
I want to create an event than can be canceled by the listener. Just like you can cancel the closing event of a winforms form in which case the form won't close.
I have already implemented a derived class from EventArgs that has a settable Cancel property as follows:
Public Class AnnounceNavigateEventArgs
Inherits EventArgs
Private _cancel As Boolean = False
''' <summary>
''' Initializes a new instance of the AnnounceNavigateEventArgs class.
''' </summary>
Public Sub New(ByRef cancel As Boolean)
_cancel = cancel
End Sub
Public Property Cancel() As Boolean
Get
Return _cancel
End Get
Set(ByVal value As Boolean)
_cancel = value
End Set
End Property
End Class
Notice that I am passing the cancel argument byRef to the constructor.
The listener I have setup is setting the property to Cancel=True. I thought ByRef meant that both _cancel and cancel would point to the same location on the stack and that setting _cancel=true would therefore make the cancel = true. But this is not the behavior I am getting. _cancel becomes true in the setter but I guess the argument to the constructor remains false.
What is the proper way to do this in vb.net?
Seth