G
govolsbaby
Not sure how to ask this so I'll try a couple ways.
So I have a class with an event...
Public Class myClass
Public Event SomethingsGoingOn()
Private Sub SomethingHappened(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Something.Happened
'code here changes some properties of myClass
RaiseEvent SomethingsGoingOn()
End Sub
End Class
Then I've got this other class with an instance of the first class
with a handler for the event...
Public Class myOtherClass
Private _myClass As myClass
Public Sub New()
_myClass = New myClass
Controls.Add(_myClass)
AddHandler _myClass.SomethingsGoingOn, AddressOf myHandler
End Sub
Public Sub myHandler()
'the code here depends on what happened, depends on the
properties of myClass
End Sub
End Class
So everything works fine. An event is raised in myClass that is
handled by myOtherClass. But suppose I'd like to myClass to do
something else based upon myOtherClass's reaction to what myClass did
in the first place. How do I get the reaction back to myClass so it
can do whatever it needs to do???
Here's a bad analogy:
I'm an instance of Dad class and I hold an instance of Kid class and
the Kid has a Wallet property. When Kid class brings home a report
card, I want to know about it (that's the event) But all I (Dad
class) want to do is look at the report card and then give the Kid
permission to go get 5 bucks out of my sock drawer if I like what I
see (that's the handler). And then the Kid's Wallet property may or
may not increase by 5 bucks. But I (Dad class) don't want to go to
the sock drawer, I want the Kid to do it (his Wallet property is
private and Dad can't get it or set it).
So I have a class with an event...
Public Class myClass
Public Event SomethingsGoingOn()
Private Sub SomethingHappened(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Something.Happened
'code here changes some properties of myClass
RaiseEvent SomethingsGoingOn()
End Sub
End Class
Then I've got this other class with an instance of the first class
with a handler for the event...
Public Class myOtherClass
Private _myClass As myClass
Public Sub New()
_myClass = New myClass
Controls.Add(_myClass)
AddHandler _myClass.SomethingsGoingOn, AddressOf myHandler
End Sub
Public Sub myHandler()
'the code here depends on what happened, depends on the
properties of myClass
End Sub
End Class
So everything works fine. An event is raised in myClass that is
handled by myOtherClass. But suppose I'd like to myClass to do
something else based upon myOtherClass's reaction to what myClass did
in the first place. How do I get the reaction back to myClass so it
can do whatever it needs to do???
Here's a bad analogy:
I'm an instance of Dad class and I hold an instance of Kid class and
the Kid has a Wallet property. When Kid class brings home a report
card, I want to know about it (that's the event) But all I (Dad
class) want to do is look at the report card and then give the Kid
permission to go get 5 bucks out of my sock drawer if I like what I
see (that's the handler). And then the Kid's Wallet property may or
may not increase by 5 bucks. But I (Dad class) don't want to go to
the sock drawer, I want the Kid to do it (his Wallet property is
private and Dad can't get it or set it).