CSDN博客

img collswang

2个窗体之间的通信

发表于2008/9/30 22:11:00  149人阅读

在一个Form里改变TextBox时  另外一个Form里TextBox的值 也随之变化

Form1: 包含个textBox1

      Public event EventHandler TextChangeValue

      {          

             add
            {
                this.textBox1.TextChanged += value;
            }
            remove
            {
                this.textBox1.TextChanged -= value;
            }

      }

 

Form2:包含一个textBox2 和button1

      public void textChange(object sender,EventArgs e)

     {

           TextBox tBox = sender as TextBox;

           textBox2.text = tBox.text;

     }

     private void button1_Click(object sender,EventArgs e)

    {

          Form1 form = new Form1();

          form.TextChangeValue += new EventHandler(textChange);

    }

0 0

相关博文

我的热门文章

img
取 消
img