单击“X”按钮并让父窗体知道它已关闭时,如何检查 MDI 子窗体的关闭事件?
问问题
1851 次
4 回答
4
You can simply listen to the FormClosed event in the MDI.
var childForm = new ChildForm();
childForm.FormClosed += new FormClosedEventHandler(form_FormClosed);
childForm.Show();
于 2011-10-19T17:51:25.733 回答
0
在 FormClosing 事件中,您可以执行
TheMainForm form = (TheMainForm)this.MdiParent()
form.AlertMe( this );
于 2011-10-19T17:45:20.780 回答
0
从 mainForm 中将关闭的事件附加到子窗体
Form mdiChild = new Form();
mdiChild.MdiParent = this;
mdiChild.Closed += (s, e) => { //... };
mdiChild.Show();
没有检查代码,但不应该那么难
于 2011-10-19T17:54:21.640 回答
0
好吧,下面的代码显示了父表单如何识别子表单是否已关闭,它还可以识别是否有任何新的子表单添加到该父表单..
private List<Form> ChildFormList = new List<Form>();
private void MyForm_MdiChildActivate(object sender, EventArgs e)
{
Form f = this.ActiveMdiChild;
if (f == null)
{
//the last child form was just closed
return;
}
if (!ChildFormList.Contains(f))
{
//a new child form was created
ChildFormList.Add(f);
f.FormClosed += new FormClosedEventHandler(ChildFormClosed); // here the parent form knows that that child form has been closed or not
}
else
{
//activated existing form
}
}
private void ChildFormClosed(object sender, FormClosedEventArgs e)
{
//a child form was closed
Form f = (Form)sender;
ChildFormList.Remove(f);
}
于 2011-10-19T18:55:50.843 回答