473,800 Members | 2,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

meaning of event handler code

in the following:
this.ExitButton .Click += new System.EventHan dler(this.ExitB utton_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 1971

"Beth" <sc***********@ msn.com> wrote in message
news:OQ******** *****@tk2msftng p13.phx.gbl...
in the following:
this.ExitButton .Click += new System.EventHan dler(this.ExitB utton_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.co m

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

"Beth" <sc***********@ msn.com> wrote in message
news:OQ******** *****@tk2msftng p13.phx.gbl...
in the following:
this.ExitButton .Click += new System.EventHan dler(this.ExitB utton_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.c om> wrote in
message news:e1******** ******@TK2MSFTN GP12.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.co m

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

"Beth" <sc***********@ msn.com> wrote in message
news:OQ******** *****@tk2msftng p13.phx.gbl...
in the following:
this.ExitButton .Click += new System.EventHan dler(this.ExitB utton_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
3699
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 should be displayed and if you scroll "up" the previous image should be displayed. So far I have: function handleMouseWheel(e)
2
4252
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 , message box pops again how to avoid it private void txtJobName_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e if(e.KeyValue == 1 MessageBox.Show("xyz") txtJobName.Focus()
3
1178
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 for saving, e.g. End and because focus does not leave the control the Validating event does not fire so I would like to be able to run the validating event for the aactive control when End is pressed on the form and then stop the save if the validation...
5
989
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 MyBase.Load End Sub Experiment B:
1
1531
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 for the control are in another combo box on the right. When I click the event, my handler is set up. In C# this does not appear to be the case. I have been going to the form designer, finding my way to the control's section, and adding...
2
1408
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
2928
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 passes the CommandName and CommandArgument of the ImageButton to the event handler. The event handler then passes data to another user control (cart) on the same page and displays some data. This all works great except for the very first time one of the...
24
55243
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 EventHandler(Onbutton_click); I want to pass more information related that event. & want to use that
1
1917
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 this when I uncomment the alert() ), which contains the __doPostBack() call. On the .VB side, the handler never gets called. BTW, the handler was created by double-clicking on the .ASPX object in the 'Design' mode. Any help would be appreciated....
0
9690
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10504
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10274
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.