初学者求问..关于委托
假设有一个父窗体FormMian
FormMian有2个按钮Bt1,Bt2,功能分别是,显示From2子窗体,显示From3子窗体
我想问的是,
在添加Bt3,其功能就是,不管你打开一个子窗体
点下Bt3,关闭FormMian父窗体
内的所有子窗体,
用委托该怎么实现?
委托今天刚讲,似懂非懂的,另求高手讲解一下
感激.. 委托
[解决办法]
private EventHandler CloseDialog;
private Form form1 = new Form1();
private Form form2 = new Form2();
private void CloseForm1(object sender,EventArgs e)
{
form1.Close();
}
private void CloseForm2(object sender, EventArgs e)
{
form2.Close();
}
public FrmMain()
{
this.CloseDialog += CloseForm1;
this.CloseDialog += CloseForm2;
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
form1.Show();
}
private void button2_Click(object sender, EventArgs e)
{
form2.Show();
}
private void button3_Click(object sender, EventArgs e)
{
CloseDialog(this, null);
}