Delegate: WinForm to implement values between forms

Source: Internet
Author: User

The software interface is as follows: Click the Receive form to open the Send form, send the form click "Send" to send to the receiving form, you can achieve the transfer of values between the form.

Receive the main code of the form:

/// <summary>        ///Open Send Form/// </summary>        /// <param name= "Sender" ></param>        /// <param name= "E" ></param>        Private voidBtnopen_click (Objectsender, EventArgs e) {Form2 F2=NewForm2 (); F2.getvaluedelegate= GetValue;//assigning a method to a delegateF2.        ShowDialog (); }        /// <summary>        ///text box with value passed to the form/// </summary>        /// <param name= "str" ></param>        voidGetValue (stringstr) {Txtvalue.text=str; }
View Code

Send the form's main code:

 Public Delegate void Getvaluedelegate (string str); // declaring a delegate         Public Getvaluedelegate getvaluedelegate; // Defining Delegates        Private void Btnsend_click (object  sender, EventArgs e)        {            if( getvaluedelegate!=null)            {                getvaluedelegate (txtvalue.text);            }        }
View Code

Do not know how to upload code, the example is very simple, I believe it should be read!

Delegate: WinForm to implement values between forms

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.