How to return value using addhandler event??

  • Thread starter Thread starter Kwok
  • Start date Start date
Hi Herfried,

The main thing is for Kwok to study it until he understands it. You've
done your bit. [I stood lazily on the side watching ;-)].

Regards,
Fergus
 
Hi Herfried.

thanks for your help

Kwok.
Herfried K. Wagner said:
Hello,



Written from scratch, untested:

\\\
Public Class Foo
Public Event Bla( _
ByVal sender As Object, _
ByVal e As BlaEventArgs _
)

Public Sub RaiseTheEvent()
Dim e As New BlaEventArgs()
RaiseEvent Bla(Me, e)
MsgBox(e.Accept.ToString())
End Sub
End Class

Public Class BlaEventArgs
Inherits EventArgs

Private m_Accept As Boolean

Public Sub New()
m_Accept = True
End Sub

Public Property Accept() As Boolean
Get
Return m_Accept
End Get
Set(ByVal Value As Boolean)
m_Accept = Value
End Set
End Property
End Class
///

Usage:

\\\
Private WithEvents m_MyFoo As Foo
.
.
.
m_MyFoo = New Foo()
.
.
.
Public Sub m_MyFoo_Bla( _
ByVal sender As Object, _
ByVal e As BlaEventArgs _
) Handles m_MyFoo.Bla
If ... Then
e.Accept = False
End If
End Sub
///
 
Back
Top