473,407 Members | 2,306 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,407 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 1941

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: cjl | last post by:
Hey all: I'm trying to write a cross-browser (IE and firefox) event handler for the mousewheel. Basically my web app is an image viewer, so if you scroll "down" with the wheel the next image...
2
by: Anil | last post by:
iam getting too many messages boxes when i include a message box in a KeyUP eventhanler function which in turn have validation if functio my code i when i press the ok button of the message box ,...
3
by: Siobhan | last post by:
H In VB6 you run the event handler code from anywher e.g Call Button1_Click ran the code behind your button1 click even Can you do this in VB.Net and if so how Our system uses shortcut keys...
5
by: Larry Lard | last post by:
Experiment A: Start a new Windows Forms project. Double click Form1. This is what is generated: Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles...
1
by: =?Utf-8?B?bXIgcGVhbnV0?= | last post by:
In the Visual Studio VB user interface when I want to create an event handler for a control, I go to the code view for the form and in a combo box at the top left I pick the control. All the events...
2
by: gouqizi.lvcha | last post by:
Does VS2005 has the ability to generate event handler code in the code behind? For example, I cannot find the UI to help me to create event like Page_Init(). Tom
1
by: cradius | last post by:
I've got a custom user control, with a DataList, that is dynamically added to the page. In the DataList is an ImageButton that, when clicked, fires off the ItemCommand event of the DataList and...
24
by: =?Utf-8?B?U3dhcHB5?= | last post by:
Can anyone suggest me to pass more parameters other than two parameter for events like the following? Event: Onbutton_click(object sender, EventArgs e)" Event handler: button.Click += new...
1
by: Cyclestump | last post by:
We're using .NET 2.0, VB. I expect a .Click event handler to be called, but it's not. When I click on the webpage link named btnSearch, the confirmSearchOK() javascipt function is called(I see...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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
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...
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.