Library tutorials & articles

Event Handling in .NET Using C#

Introduction

In this article I discuss the event handling model in .NET using C#. The discussion starts with an introduction to the concept of delegates and then it extends that concept to events and event handling in .NET. Finally, I apply these concepts to GUI event handling using windows forms. Complete code is provided in each step of the discussions.

Event handling is familiar to any developer who has programmed graphical user interfaces (GUI). When a user interacts with a GUI control (e.g., clicking a button on a form), one or more methods are executed in response to the above event. Events can also be generated without user interactions. Event handlers are methods in an object that are executed in response to some events occurring in the application. To understand the event handling model of .Net framework, we need to understand the concept of delegate.

Comments

  1. 25 Apr 2007 at 04:18

    While it's very nice to know the "How" when explaining syntax, more importantly is they "why" in terms of practical real-life use within a C# application.  It would be nice of you would have included some true examples of when you would need to use one and why.

  2. 24 Nov 2005 at 15:04

    This is one of the best articles i have come across on Delegates and Event.. Good Job!

  3. 02 Jun 2004 at 12:03

    Line:


    public class MyEventArgs  EventArgs {


    should read:


    public class MyEventArgs : EventArgs {


    Otherwise, great article!

  4. 22 Apr 2004 at 17:24

    Can anyone help me pls!!!


    I am facing a big problem to code the gui buttons!! I am doing a C# project. this project consists of a telephone graphical user interface!!


    can anyone tell me what can i do to code the number buttons to display the telephone number into a textfield...


    I need this urgent plsssss!!!!!!


    Thanks for your help!!!!!!

  5. 28 Jul 2003 at 16:32

    I need to know how can I trap an Outlook Event (Saving an Item) using C#. Any example will be highly appreciated.


    Thanks in advance!!

  6. 12 Jul 2003 at 03:52

    How can I create asynchrous events?
    Using delegates and events I get synchronous calls?
    Please advise.

  7. 28 Apr 2003 at 17:34

    Hi,


    I am using certain, COM Components, I need to know the delegate signature, to create event handler. Is there any tools to do this? or if I need to do manually which is the easiast way to know the exact signature of those events raised by the COM components.

  8. 20 Mar 2003 at 06:56

    Very good example. it can be better hadling browser events, with .NET of course.

  9. 01 Jan 1999 at 00:00

    This thread is for discussions of Event Handling in .NET Using C#.

Leave a comment

Sign in or Join us (it's free).

AddThis

Related discussion

Related podcasts

  • CodeCast Episode 4: State of .NET, IE8, ASP.NET MVC, and O'Reilly Media

    CodeCast Episode 4: State of .NET, IE8, ASP.NET MVC, and O'Reilly MediaHosts Ken Levy and Markus Egger discuss the new State of .NET events, IE8, ASP.NET MVC, followed by an interview from PDC with two editors from O'Reilly Media. More on ASP.NET MVC can be found at http://asp.net/mvc. Interview...

Events coming up

  • Dec 6

    Developing AJAX Web Applications with Castle Monorail

    London, United Kingdom

    Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!