Understanding Event Handling in .NET
terms, an event is the resultant outcome of an action. In the programming
terms, when the user does some action such clicks a button then the user
is directed to some other window or dialog box.
If clicking a button is an action then the outcome of that action is known as event. In .NET Framework an event enables objects in a class to notify other objects that an action has been performed and they should react to this. Events in .NET Framework are based on publisher-subscriber model. The class that issues or publishes an event is called the publisher of the event and the class that registers to the published event is called the subscriber of the event.
When talking about events you should be aware of three most important concepts of events. They are event handlers, event arguments, and delegates. An event handler is a process of what and how the outcome should be displayed in response to the event notification. The event handlers take parameters similarly to the values that an event generates. By default the event handlers take two parameters and return no data. The first parameter describes the object on which the event occurred and the second parameter contains the event arguments.
The event arguments describe the data associated with an event. This data is sufficient enough to handle the event. The event arguments are of types EventArgs. When an event is raised, means when some button is clicked, the event arguments are transferred to the event handlers. Delegates in .NET Framework are used to attach code to the events. A delegate is a class that allows you to create objects that store the reference to methods that does not return any value and that accepts two arguments. Delegates can be compared to function pointers in other languages.
you can handle events through three ways. These are:
to our mailing list and receive new articles Note
: We never rent, trade, or sell my email lists to Visit
.NET Programming Tutorial Homepage ______________________________________________________
to our mailing list and receive new articles
: We never rent, trade, or sell my email lists to
Visit .NET Programming Tutorial Homepage