所以我将Form2中的委托从Form2链接到This_Hide()函数,然后我将Form3中的委托链接到Form2中的委托(正如我所说的那样链接到Form1中的函数)但我感到困惑的是,尽管Form2处于CLOSED状态仍然有效当我创建Form3的实例时。如果Form.Close()方法关闭Form2并处理它,Form3中的委托仍然可以从Form2调用函数(委托)..?
namespace TestingMachine
{
public delegate void FxDelegate();
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Form2 fr2 = new Form2();
fr2.Delegate_Father_Hide = new FxDelegate(This_Hide);
fr2.Show();
}
public void This_Hide()
{
this.Hide();
}
}
}
namespace TestingMachine
{
public partial class Form2 : Form
{
public FxDelegate Delegate_Father_Hide;
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Form3 fr3 = new Form3();
fr3.Delegate_Hide_Grandfather = new FxDelegate(Hide_Grandfather);
fr3.Show();
this.Close();
}
public void Hide_Grandfather()
{
Delegate_Father_Hide();
}
}
}
namespace TestingMachine
{
public partial class Form3 : Form
{
public FxDelegate Delegate_Hide_Grandfather;
public Form3()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Delegate_Hide_Grandfather();
}
}
}