Click here to Skip to main content
Licence CPOL
First Posted 7 Aug 2006
Views 12,690
Bookmarked 14 times

Delegate Event

By | 7 Aug 2006 | Article
Delegate Event

Sample Image - Delegate_Events.jpg

Introduction

This is one simple example for handling delegate events. Delegate event one of the advance concept in c#.net. We can pass the values between two control by using delegate events.

In this artical we have to controls. one is top control and another one is bottom control. Below we can see, how to pass the values between two controls by using delegate events.

Top Control :

This control having one text box and one sibmit button. Now, we are going to create a event in the control to pass the text box value to another control.

Firest we have to create a event handler before the declaration of the class.

public delegate void TextEventHandler(Object sender, TextEventArgs e);

Second we have to create event args to pass these value.

public class TextEventArgs : EventArgs
{
private string text;
public TextEventArgs(string textValue)
{
text = textValue;
}
public string Text
{
get { return text; }
}
}
Third passing the value to the args.

TextEvent(this, new TextEventArgs(textBox1.Text));

Now, we can see. how to access these values from another control.

Bottom Control : In this control, just we have to initialize the event. how to initialize the event...

TopControl.TextEvent += new TextEventHandler(SetTextBox);

private void SetTextBox(object sender, DelegateEvents.TextEventArgs e)
{
textBox1.Text = e.Text;
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

raajaak

Software Developer
General Physics Corporation (GP)
India India

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 PinmemberAndyJudd6:16 2 Mar '10  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 7 Aug 2006
Article Copyright 2006 by raajaak
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid