C#窗体委托回调

         We have two forms.Each form has a textBox,and Form1 has a Button beside the textBox.After click on the Button ,Form2 shows with also a textBox on it and Form1 is background where you can still see it. Now what we want is that,every letter you type in the Form2's textBox should immediately showed in the Form1's textBox!

 

Let's make it!

Here is is the key code we need to type in "ff2.cs".

        public delegate void a(string s);
        public event a txtchang;
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (txtchang != null)
                txtchang(textBox1.Text);
        }

 Then ,let's see the code in ff1. 

private void button1_Click(object sender, EventArgs e)
        {
            ff2 form = new ff2();
            form .txtchang +=new ff2.a (textchang );
            form.Show();
        }
public void textchang(string s)
        {
            textBox1 .Text =s;
           
        }

  Ctrl+F5,here we go ,problem solved!!

 

 

Best Wishes,Jess

2012-12-13

 

 

 

posted @ 2012-12-12 09:53  JessZhu  阅读(260)  评论(0编辑  收藏  举报