Using a delegate to pass a value

Source: Internet
Author: User

public partial class Form2:form
{
Public Form2 ()
{
InitializeComponent ();
}
Public Form2 (String Str,delegate de): this ()//Call the current empty constructor
{
Label1. Text = str; Assign value
this.de = de;//Assignment
}
private void Form2_load (object sender, EventArgs e)
{

}
Private Delegate de;//define delegate Type field
private void Button1_Click (object sender, EventArgs e)
{
String strmsg = TextBox1.Text;
if (de! = null)
{
De (strmsg); Delegate type
}
This. Close ();
}
}

 public Main1 ()
        {
             InitializeComponent ();
       }

private void Button1_Click (object sender, EventArgs e)
{
string content = TextBox1.Text;
Form2 frm2 = new Form2 (CONTENT,MSGSTR); Initialize constructors and assign values, with arguments requiring a delegate type (note: delegate type)
Frm2. Show ();
}
private void MsgStr (String str)
{
TextBox2.Text = str;
}
}

Using a delegate to pass a value

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.