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