1. 程式人生 > >利用委託重新整理父窗體

利用委託重新整理父窗體

父窗體:
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        //事件處理方法
        void frm_TransfEvent(string value)
        {
            textBox1.Text = value;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 frm 
= new Form2(); //註冊事件 frm.TransfEvent += frm_TransfEvent; frm.ShowDialog(); } } 子窗體: public delegate void TransfDelegate(String value); public partial class Form2 : Form { public Form2() { InitializeComponent(); }
public event TransfDelegate TransfEvent; private void button1_Click(object sender, EventArgs e) { //觸發事件 TransfEvent(textBox1.Text); this.Close(); } }