You need to connect the MyBall event to the pitcher.catches Method. Since the Myball is declared in the method you can't use the WithEvents keyword.
To connect the handler at runtime you use AddHandler
.
Dim myBall As New Ball
Dim pitcher As New Pitcher
AddHandler myBall.BallInPlay, AddressOf pitcher.catches
myBall.OnBallInPlay(New BallEventArgs(10, 20))
To disconnect the handler you use RemoveHandler
.
RemoveHandler myBall.BallInPlay, AddressOf pitcher.catches
EDIT
I just understood the problem/missing part. You just need to define the Pitcher.MySender
since:
- it is declared with
WithEvents
keyword and you already invoke the
catches
method viaHandles mySender.BallInPlay
Dim myBall As New Ball Dim pitcher As New Pitcher pitcher.mySender = myBall myBall.OnBallInPlay(New BallEventArgs(10, 20))