Delegates and events

Source: Internet
Author: User

First, click the Saywords button, directly trigger events, display data

Second, start editing the event code, where a Jiafang class and a message (the owning EventArgs, the event argument) are created to encapsulate the properties

1, the Jiafang classnamespacedelegate and event again_and_again{//create a class of party a      Public classJiafang {//Add members to party a        Private string_word;  Public stringWord {Get{return_word;} Set{_word =value;} }        Private string_name;  Public stringName {Get{return_name;} Set{_name =value;} }         //Define an event         Public EventWeituohandler events; //define a function to trigger this event         Public voidsaywords () {if(events!=NULL) {Events ( This,NewMessage () {word="I am party a"}); }        }             }}2, the class of messagenamespacedelegate and event again_and_again{ Public classMessage:eventargs {Private string_word;  Public stringWord {Get{return_word;} Set{_word =value;} }    }}3, Eventsnamespacedelegate and event again_and_again{//define a delegate     Public Delegate voidWeituohandler (Objecta,message msg);  Public Partial classForm1:form {Jiafang x;  PublicForm1 () {InitializeComponent (); X=NewJiafang ();"Party"; Label1.; = x_events;//x-click events        }        voidX_events (ObjectA, message msg) {TextBox1.Text="who are you ?"; TextBox1.Text+="\ t"+Msg.        Word; }        Private voidButton1_Click (Objectsender, EventArgs e)//saywords Button{x.saywords ();//trigger function, function to raise event        }    }}

Delegates and events

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.