Delegate implementation form delivery

Source: Internet
Author: User

A delegate can pass a method as a parameter.

     Public Delegate void Dgfillareas (string IDs,string names);  // Defining Delegates     // defining a delegate is a    way to determine the type of signature (return value/parameter) that can be stored in this delegate object. // If this delegate is a description of this type of delegate object in the future can only store  no return value  has two string parameter method, the delegate can store multiple such signature method
        Private voidBtnchoice_click (Objectsender, EventArgs e) {frmareas frm=NewFrmareas (Fillareas);//passing a method as a parameterfrm.        ShowDialog (); }         Public voidFillareas (stringIdsstringNames//the concrete implementation of the Entrustment method        {             This. Txtdistrict.text =names;  This. Txtdistrict.tag =IDs; }
        Dgfillareas dgfrm;          // define a delegate type         Public Frmareas (Dgfillareas dgfrm)      // Secondary form constructor, accepts the delegate         {            InitializeComponent () returned from the main form;             this. dgfrm = dgfrm;        
           Dgfrm. Invoke (AIDS. ToString (). Substring (01), Anams. ToString (). Substring (01));   // invoking a Delegate method

The advantage of this method is that the method is passed from the main form to the secondary form as a parameter, so the secondary form can only invoke the delegate's method, not the public member of the main form.

Delegate implementation form delivery

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: info-contact@alibabacloud.com 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.