473,545 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Raise an event from another event

Hi group;

Let say I have an object called Account, that raises an event called
AccountLow with its owns EventArgs, and when this event gets raised, I
will like to raise another custom event called AccountGotLowAm ount and
passes AccountLow’s EventArgs along with the new event.

How do I do this?


Jul 29 '07 #1
5 1997
Hi Mike,

Why don't you just call the method Accou ntGotLowAmound, passing the sender
and the e (event args) to that?

It is much easier, better to mainenance and I thought that you cannot make
your own events because that is a part of Net.

Cor
"Mike" <mi**@hitnext.c omschreef in bericht
news:7291D5D57A 274E39BEA6054E7 75601F7@PHBASE. ..
Hi group;
Let say I have an object called Account, that raises an event called
AccountLow with its owns EventArgs, and when this event gets raised, I will
like to raise another custom event called AccountGotLowAm ount and passes
AccountLow's EventArgs along with the new event.
How do I do this?
Jul 29 '07 #2
Well i guess you can do 2 things

When you raise event AccountLow inmediatly raise AccountGotLowAm ount
or crate a local handler for AccountLow ( in the sub new for instance with addhandler ) in the object and from this handler raise AccountGotLowAm ount

Note that in both situations AccountLow will always be raised before AccountGotLowAm ount is raised
hth

Michel Posseth


"Mike" <mi**@hitnext.c omschreef in bericht news:7291D5D57A 274E39BEA6054E7 75601F7@PHBASE. ..
Hi group;





Let say I have an object called Account, that raises an event called AccountLow with its owns EventArgs, and when this event gets raised, I will like to raise another custom event called AccountGotLowAm ount and passes AccountLow's EventArgs along with the new event.





How do I do this?



Jul 29 '07 #3
brr,

Thanks Mike, I had read a book about C# during my holiday that did describe
this in another way, however I thought there were more errors in that book.
Of course you can raise an event.

Although, I keep the by me posted solution still better for maintenance.

:-)

Cor
"Michel Posseth [MCP]" <MS**@posseth.c omschreef in bericht
news:OZ******** ******@TK2MSFTN GP04.phx.gbl...
Well i guess you can do 2 things

When you raise event AccountLow inmediatly raise AccountGotLowAm ount
or crate a local handler for AccountLow ( in the sub new for instance with
addhandler ) in the object and from this handler raise AccountGotLowAm ount

Note that in both situations AccountLow will always be raised before
AccountGotLowAm ount is raised
hth

Michel Posseth


"Mike" <mi**@hitnext.c omschreef in bericht
news:7291D5D57A 274E39BEA6054E7 75601F7@PHBASE. ..
Hi group;
Let say I have an object called Account, that raises an event called
AccountLow with its owns EventArgs, and when this event gets raised, I will
like to raise another custom event called AccountGotLowAm ount and passes
AccountLow's EventArgs along with the new event.
How do I do this?
Jul 29 '07 #4
Hello Mike

In answer to the e-mail you send ( i like to keep it in the group so anyone
can benefit and / or join in the discussion )

here are 2 simple examples

Raiseevent option :
Public Class Form1
Private WithEvents account As New Account
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
account.DosomeC alcOnAccount()
End Sub
Private Sub account_eAccoun tLow(ByVal Amount As Decimal) Handles
account.eAccoun tLow
MsgBox("eAccoun tLow :Amount:" & Amount.ToString )
End Sub
Private Sub account_eAccoun tGotLowAmount(B yVal Amount As Decimal)
Handles account.eAccoun tGotLowAmount
MsgBox("eAccoun tGotLowAmount :Amount:" & Amount.ToString )
End Sub
End Class
Public Class Account
'option 1
Public Event eAccountLow(ByV al Amount As Decimal) 'ofcourse the event
arguments could be anything you like
Public Event eAccountGotLowA mount(ByVal Amount As Decimal)
Public Sub New()
'nothing needed here
End Sub
Public Sub DosomeCalcOnAcc ount()
'do some stuff in a sub routine
'dummy routine
Dim amount As Decimal = 1000
Do Until amount = 100
amount -= 1
Loop
'hey the account got low :-)
'simplest solution ( although i like the next example more as it
binds both events )
RaiseEvent eAccountLow(amo unt)
RaiseEvent eAccountGotLowA mount(amount)
End Sub
End Class

Private handler option :
Public Class Form1
Private WithEvents account As New Account
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
account.DosomeC alcOnAccount()
End Sub
Private Sub account_eAccoun tLow(ByVal Amount As Decimal) Handles
account.eAccoun tLow
MsgBox("eAccoun tLow :Amount:" & Amount.ToString )
End Sub
Private Sub account_eAccoun tGotLowAmount(B yVal Amount As Decimal)
Handles account.eAccoun tGotLowAmount
MsgBox("eAccoun tGotLowAmount notice that i am raised through the
clas`s handler :Amount:" & Amount.ToString )
End Sub
End Class
Public Class Account
'option 1
Public Event eAccountLow(ByV al Amount As Decimal) 'ofcourse the event
arguments could be anything you like
Public Event eAccountGotLowA mount(ByVal Amount As Decimal)
Public Sub New()
AddHandler eAccountLow, AddressOf sAccountGotLowA mount
End Sub
Private Sub sAccountGotLowA mount(ByVal Amount As Decimal)
RaiseEvent eAccountGotLowA mount(Amount)
End Sub
Public Sub DosomeCalcOnAcc ount()
'do some stuff in a sub routine
'dummy routine
Dim amount As Decimal = 1000
Do Until amount = 100
amount -= 1
Loop
'hey the account got low :-)
RaiseEvent eAccountLow(amo unt)
End Sub
End Class

when i tested this code it turned out that i was wrong in a previous
asumption
cause in the second example eAccountGotLowA mount is externally raised before
the event eAccountLow.

hth

Michel



"Mike" wrote:
Hi group;

Let say I have an object called Account, that raises an event called
AccountLow with its owns EventArgs, and when this event gets raised, I
will like to raise another custom event called AccountGotLowAm ount and
passes AccountLow’s EventArgs along with the new event.

How do I do this?

Jul 29 '07 #5

I already thought you were on a holliday , i honestly missed you ;-)

Thanks Mike, I had read a book about C# during my holiday that did describe
this in another way,
yes probably with delegates ( wich you can also do in VB , even bether
events and raisevents are automaticly converted by the compiler to exact the
same IL constructs as with delegates , i just find the VB syntax so much
easier )

regards

Michel


"Cor Ligthert[MVP]" wrote:
brr,

Thanks Mike, I had read a book about C# during my holiday that did describe
this in another way, however I thought there were more errors in that book.
Of course you can raise an event.

Although, I keep the by me posted solution still better for maintenance.

:-)

Cor
"Michel Posseth [MCP]" <MS**@posseth.c omschreef in bericht
news:OZ******** ******@TK2MSFTN GP04.phx.gbl...
Well i guess you can do 2 things

When you raise event AccountLow inmediatly raise AccountGotLowAm ount
or crate a local handler for AccountLow ( in the sub new for instance with
addhandler ) in the object and from this handler raise AccountGotLowAm ount

Note that in both situations AccountLow will always be raised before
AccountGotLowAm ount is raised
hth

Michel Posseth


"Mike" <mi**@hitnext.c omschreef in bericht
news:7291D5D57A 274E39BEA6054E7 75601F7@PHBASE. ..
Hi group;
Let say I have an object called Account, that raises an event called
AccountLow with its owns EventArgs, and when this event gets raised, I will
like to raise another custom event called AccountGotLowAm ount and passes
AccountLow's EventArgs along with the new event.
How do I do this?

Jul 29 '07 #6

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

Similar topics

1
10498
by: Dan Cimpoiesu | last post by:
I have a remoting object, derived from MarshalByRefComponent, that I instantiate on the client side, with Activator.GetObject. Can I receive events fired on the server, on the client? How?
2
1594
by: IcedCrow | last post by:
Subject says it all. I want to raise an event in Sub New of a class but it is not being raised to my client app. I can raise events just fine in other procedures... just not sub new. Why is this? Thanks in advance!
12
2924
by: Vittorio Pavesi | last post by:
Hello, is it possible to manually raise the event Elapsed of the timer object ? Vittorio
4
4519
by: Jeremy | last post by:
I have a combobox with a SelectionChangeCommitted event handler, and am having a problem raising this event. For example, raiseEvent mycombobox.SelectionChangeCommitted gives me an error about not being ended properly. But it won't accept parameters either. What's the trick here?
2
2071
by: Pietro | last post by:
Hello, somebody know how to raise an event from a nested class? I have two classes, the class1 with 1 events, and a nested class (class2) inside the class1. So... How can I raise class1 events from the class2? Public Class class1 Public Shared Event Evento1(ByRef sender As Object) Public Class class2
1
9932
by: Anonieko | last post by:
I know Visual Studio lacked support on easily writing code to raise events from a ascx user control ( because you have to hand write them). (http://codebetter.com/blogs/brendan.tompkins/archive/2004/10/06/27795.aspx) Question: Is it better and easier now in ASPNET 2.0 , meaning VS 2005?
3
2119
by: =?Utf-8?B?Ulc=?= | last post by:
I constructed a new Class with some private members. I would like an event to be raised on the moment the value of one of those private members is changed. How do I define an event for that private member and how do I raise the event? -- RW
2
9138
by: Sin Jeong-hun | last post by:
Suppose class Engine do something in another thread and raise events. class Engine { Thread Worker; public event ... EngineMessage; public void Start() { Worker=new Thread(new ThreadStart(Run)); Worker.Start();
11
4008
by: nadeem_far | last post by:
Hello, I am working on a c# project using framework 1.1. Since its a console application,no windows forms are being used. I am trying to implement event driven classes that just want to raise the event and continue working( like fire and forget - do not wait for the event handler in client to finish.) I have gone through alot of the...
0
7499
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7432
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7689
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7943
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7456
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7786
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3490
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1919
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
743
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.