Two forms commission to pass by value

public partial class Form4 : Form
    {
        public string str = "";
        public Form4()
        {
            InitializeComponent();
        }

        private void Form4_Load(object sender, EventArgs e)
        {
            Form5 f5 = new Form5();
            f5.change = new Form5.mydelegate (ChangeText); // bind to a method of form5  
            f5.Show();
        }


     public  void ChangeText(string s)
    { 
    This.label1.Text = S;} // Event processing method }
}

  

 public partial class Form5 : Form
    {
        public delegate void mydelegate (string ss); // define a delegate type of encapsulation prototype
        public Form5()
        {
            InitializeComponent();
        }
        
        public mydelegate change;
        private void button1_Click(object sender, EventArgs e)
        {
            change (this.label1.Text); // change triggered by clicking on the button
        }
    }

  

Guess you like

Origin www.cnblogs.com/1521681359qqcom/p/11875738.html