473,395 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Event with response?

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).

Sep 18 '08 #1
5 978
By using something else than System.EventArgs for the e argument.

For example see the FormClosing event. Its argument provides a Cancel
property you can use if the event handler wants to cancel the close.

Does it sounds like what you are looking for ? Do you need a sample ?

--
Patrice

<go********@gmail.coma écrit dans le message de groupe de discussion :
4a**********************************...oglegroups.com...
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).
Sep 18 '08 #2
On Sep 18, 9:37*am, "Patrice" <http://www.chez.com/scribe/wrote:
By using something else than System.EventArgs for the e argument.

For example see the FormClosing event. Its argument provides a Cancel
property you can use if the event handler wants to cancel the close.

Does it sounds like what you are looking for ? Do you need a sample ?

--
Patrice
Thanks. No, I don't think I need a sample. Sometimes I just need a
little push in the right direction.
Sep 18 '08 #3
On Sep 18, 10:23*am, govolsb...@gmail.com wrote:
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).
One interesting thing you can do is define a return type on the
delegate that drives the event. I'm not sure if you can do this in VB,
but I know it's valid in C#.

Please see: http://sethrowe.blogspot.com/2008/09...rom-event.html
for a quick rundown and sample.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
Sep 18 '08 #4
What I had in mind is mostly the On<Eventpattern rather than raising
directly the event where needed. This way it's easy to change something
before/after the event is raised...

--
Patrice

<go********@gmail.coma écrit dans le message de groupe de discussion :
54**********************************...oglegroups.com...
On Sep 18, 9:37 am, "Patrice" <http://www.chez.com/scribe/wrote:
>By using something else than System.EventArgs for the e argument.

For example see the FormClosing event. Its argument provides a Cancel
property you can use if the event handler wants to cancel the close.

Does it sounds like what you are looking for ? Do you need a sample ?

--
Patrice

Thanks. No, I don't think I need a sample. Sometimes I just need a
little push in the right direction.

Sep 19 '08 #5
go********@gmail.com wrote:
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()
.. . .

More usually, that's written as :

Public Class myClass

Public Event XHappening( sender as Object, e as EventArgs )

Public Event XHappened( sender as Object, e as EventArgs )

Protected Sub OnXHappening(e As System.EventArgs)
RaiseEvent XHappening( Me, e )
End Sub

Protected Sub OnXHappened(e As System.EventArgs)
RaiseEvent XHappened( Me, e )
End Sub

End Class

You'd often have custom EventArgs classes for each event; the *ing ones
should have a way of "cancelling" the event, the *ed ones need not have.
(that's a gross generalisation, but I've found it useful).
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(sender as Object, e as EventArgs)
' the code here depends on what happened, depends on the
' properties of myClass

If TypeOf sender is myClass Then
With DirectCast( sender, myClass )
... use whatever properties you like here
End With
End If

End Sub
End Class

HTH,
Phill W.
Sep 19 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: angus | last post by:
Hi, guys, I am trying to build an event calendar using asp, i want to display a redot whenever there is an event on that day. i built the ms access database so that one day can have more than one...
7
by: Jay Douglas | last post by:
Hello all, I have a asp.net page that creates a pdf on the fly and sends the pdf down to the browser. When calling the page up in IE the Page_Load event is fried twice. This doesn't happen with...
6
by: MooreSmnith | last post by:
When I navigate to the next page using Response.Rediect("MyNextPage.aspx") current page Page_Load event is called. What I may wrongly understood is that post back will happen whenever there is any...
2
by: glenn | last post by:
Hi folks, I am trying to determine which item in a DropDownList Web control has been selected. I have posted an OnSelectedIndexChanged subroutine in my code with a reference to the subroutine...
3
by: tess | last post by:
I've created a small database with the purpose of tracking events, who is invited, who attends, and all related information. I"ll try to explain here what I've done so far and where I need help....
11
by: J055 | last post by:
Hi I have a dropdown control which is constructed in another dropdown control SelectedIndexChanged event protected void ddlParamType_SelectedIndexChanged(object sender, EventArgs e) { //...
2
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite...
0
by: rtwPhoenix | last post by:
To install a button on-click event that automatically installs a .vcs event for a personal calendar. This is written in .net vb. From this you should be able to get a good idea of how this works...
6
by: Mel | last post by:
I have a website that allows the user to generate a new quote. When they are finished creating the quote, it brings them to the final page (called the Goodbye.aspx page) which just states the...
15
by: Phillip B Oldham | last post by:
Are there any python event driven frameworks other than twisted?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.