Results 1 to 4 of 4

Thread: Events in C# language

  1. #1
    Geek_Guest
    Guest

    Events in C# language

    Question asked by Visitor Mansoor

    Can someone explain me events in c# language? any example will help.


  2. #2
    Junior Member
    Join Date
    Apr 2007
    Answers
    8

    Re: Events in C# language

    First I would like u to understand what the event is?
    Event in simple meaning is any interaction of a user to the system that causes the system to take actions is event. E.g. when you (a user) click a link (interaction) in this page you initiate an ineraction with this page. Now this ineraction (event) would cause the system to take actions. The event is like waking call to the system. A notification message to the system that says that any thing happened.

    the whole processing model is based on this
    user<-->Ineraction<-->System<-->Execute Event Code
    this is called event driven model.

    In C# or VB the event is managed by the delegates that take any event method as an argument and execute proper method whenever user interact with the system. You define event code for any contol or page in seperate method like Page_Load for page loading event or button1_Click method for button..
    e.g
    protected void button_Click(object sender, EventArgs e)
    {
    //Your implementaion
    }

    you register this event as:
    button1.OnClik+=new EventHandler(button_Click); //Delegate

    But behind the scenes windows OS model manages these events through window messages running on different threads. So you can say the event model in C# is higher level of abstraction of this window messaging.
    For further reading please refer to any C# books or MSDN Online.

    Last edited by bhaskarjha; 04-09-2007 at 11:48 AM.

  3. #3
    Junior Member
    Join Date
    Jan 2007
    Answers
    1

    Re: Events in C# language

    In google search for 'function X ' you'll get a good article on Events and exception handling and many more. It's very good set of articles for beginner


  4. #4
    Junior Member
    Join Date
    Oct 2012
    Answers
    1

    Re: Events in C# language

    class DateExample
    {
    private readonly DateTime _date;

    public DateExample(DateTime date)
    {
    _date = date;
    }

    public DateTime Date
    {
    get { return _date; }
    }
    }

    //Create header and column
    grid.Headers.Add(new Header());
    grid.Headers[0].Add(new Column("Date"));

    //Configure the header
    grid.Headers[0].StretchMode = ColumnStretchMode.All;
    grid.Headers[0][0].SortDirection = SortDirection.Ascending;
    grid.Headers[0]["Date"].Format = new StringFormat("d", new CultureInfo("fr-FR"));

    //Populate grid with random data
    Random random = new Random();
    BindingList<DateExample> source = new BindingList<DateExample>();
    for (int i = 0; i < 6; ++i)
    {
    source.Add(new DateExample(DateTime.Now + TimeSpan.FromDays(random.Next(1000))));
    }
    grid.DataSource = source;

    Unformatted values sorting
    .net grid is very helpful tutorial

    Last edited by admin; 11-04-2012 at 10:05 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact