简单的C#委托

'在主窗体Form1中声明

 private void 插入新编码ToolStripMenuItem_Click(object sender, EventArgs e)

        {

            Form2 f2 = new Form2();

            f2.FatherRefresh += new Form2.DoAction(Form1_Load);

            f2.ShowDialog();

        }

'在子窗体中加入如下声明

public delegate void DoAction(object sender, EventArgs e);

        public event DoAction FatherRefresh;

'在关闭Form2的时候调用FatherRefresh函数

private void Form2_FormClosed(object sender, FormClosedEventArgs e)

        {

            FatherRefresh(sender, e);

        }

你可能感兴趣的:(C#)