471,321 Members | 1,747 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

meaning of event handler code

in the following:
this.ExitButton.Click += new System.EventHandler(this.ExitButton_Click);

if I saw an equation, such as y +=x;
then y = y+x.

But what is the meaning in the event handler. I realize it is adding an
event handler for the click event of the exit button, but how do i reason
through the 2 step process inferred by the += equation.

Beth
Nov 27 '05 #1
3 1838

"Beth" <sc***********@msn.com> wrote in message
news:OQ*************@tk2msftngp13.phx.gbl...
in the following:
this.ExitButton.Click += new System.EventHandler(this.ExitButton_Click);

if I saw an equation, such as y +=x;
then y = y+x.

But what is the meaning in the event handler. I realize it is adding an
event handler for the click event of the exit button, but how do i reason
through the 2 step process inferred by the += equation.


+= with events means add an event handler to the set. It is basically a
specialization of hte += operator to hook up event handlers, unlike the
equation y = y+x, += just specifcally means "hook up this handler to the
event." It calls the add handler for the event. There isn't a Click = Click
+ Handler because it isn't possible to assign to an event from outside of
the class.

If I understand waht you are asking, anyway.
Nov 27 '05 #2
It goes a little bit beyond that, and has it's roots in how delegates
are handled.

When you attach a delegate to an event handler, the delegate at the end
of the list ends up being assigned the reference to the delegate that is
being attached. Your invocation list is actually a linked list.

So, when you use += to attach a delegate to an event handler, it kind of
makes sense when you expand it now to event = event + new delegate, because
what is happening is that you are taking the invocation list, and adding the
event handler to the end of the invocation list.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:ub****************@TK2MSFTNGP12.phx.gbl...

"Beth" <sc***********@msn.com> wrote in message
news:OQ*************@tk2msftngp13.phx.gbl...
in the following:
this.ExitButton.Click += new System.EventHandler(this.ExitButton_Click);

if I saw an equation, such as y +=x;
then y = y+x.

But what is the meaning in the event handler. I realize it is adding an
event handler for the click event of the exit button, but how do i reason
through the 2 step process inferred by the += equation.


+= with events means add an event handler to the set. It is basically a
specialization of hte += operator to hook up event handlers, unlike the
equation y = y+x, += just specifcally means "hook up this handler to the
event." It calls the add handler for the event. There isn't a Click =
Click + Handler because it isn't possible to assign to an event from
outside of the class.

If I understand waht you are asking, anyway.

Nov 27 '05 #3
Thank you, that makes sense.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:e1**************@TK2MSFTNGP12.phx.gbl...
It goes a little bit beyond that, and has it's roots in how delegates
are handled.

When you attach a delegate to an event handler, the delegate at the end
of the list ends up being assigned the reference to the delegate that is
being attached. Your invocation list is actually a linked list.

So, when you use += to attach a delegate to an event handler, it kind
of makes sense when you expand it now to event = event + new delegate,
because what is happening is that you are taking the invocation list, and
adding the event handler to the end of the invocation list.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:ub****************@TK2MSFTNGP12.phx.gbl...

"Beth" <sc***********@msn.com> wrote in message
news:OQ*************@tk2msftngp13.phx.gbl...
in the following:
this.ExitButton.Click += new System.EventHandler(this.ExitButton_Click);

if I saw an equation, such as y +=x;
then y = y+x.

But what is the meaning in the event handler. I realize it is adding an
event handler for the click event of the exit button, but how do i
reason through the 2 step process inferred by the += equation.


+= with events means add an event handler to the set. It is basically a
specialization of hte += operator to hook up event handlers, unlike the
equation y = y+x, += just specifcally means "hook up this handler to the
event." It calls the add handler for the event. There isn't a Click =
Click + Handler because it isn't possible to assign to an event from
outside of the class.

If I understand waht you are asking, anyway.


Nov 28 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by cjl | last post: by
2 posts views Thread by Anil | last post: by
1 post views Thread by =?Utf-8?B?bXIgcGVhbnV0?= | last post: by
2 posts views Thread by gouqizi.lvcha | last post: by
24 posts views Thread by =?Utf-8?B?U3dhcHB5?= | last post: by

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.