C#winform判断子窗口是否已关闭或在关闭的时候触发事件

怎么样判断C#winform怎么判断窗口是否已经关闭或在关闭窗口的时候可以触发一个什么事件。

private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show(this, "确认关闭?",
"提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
{
ArrayList alist = new ArrayList();
alist.Add("newCODDemo.exe");
alist.Add("newCODDemo.vshost.exe");
for (int i = 0; i < alist.Count; i++)
{
if (System.Diagnostics.Process.GetProcessesByName(alist[i].ToString()).Length <= 0)
{
try
{
//System.Diagnostics.Process.Start(processName);
System.Diagnostics.Process.GetCurrentProcess().Kill();
}
catch
{
MessageBox.Show(this, "关闭向导出错", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
}

注册FormClosing事件,既然关闭了窗体,那相关进程也要关掉。免得一直占用内存资源。
温馨提示:内容为网友见解,仅供参考
第1个回答  2010-05-29
关于窗口关闭事件有两个,一个是关闭后的closed和关闭中的closing!前者应该可以实现子窗体关闭向父窗体发送或设置一个值作为窗口关闭的通知,后者通常是用来做个关闭询问的功能,可取消窗口关闭
第2个回答  2020-05-25
private
void
MainForm_FormClosing(object
sender,
FormClosingEventArgs
e)
{
if
(MessageBox.Show(this,
"确认关闭?",
"提示",
MessageBoxButtons.OKCancel,
MessageBoxIcon.Warning)
==
DialogResult.OK)
{
ArrayList
alist
=
new
ArrayList();
alist.Add("newCODDemo.exe");
alist.Add("newCODDemo.vshost.exe");
for
(int
i
=
0;
i
<
alist.Count;
i++)
{
if
(System.Diagnostics.Process.GetProcessesByName(alist[i].ToString()).Length
<=
0)
{
try
{
//System.Diagnostics.Process.Start(processName);
System.Diagnostics.Process.GetCurrentProcess().Kill();
}
catch
{
MessageBox.Show(this,
"关闭向导出错",
"提示",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
}
}
}
注册FormClosing事件,既然关闭了窗体,那相关进程也要关掉。免得一直占用内存资源。
第3个回答  2020-02-25
不需要api,不过你hide可不是关闭,只是隐藏了而已。你可以这样
bool
isopen=false;
foreach
(form
childrenform
in
this.mdichildren)
{
if
(childrenform.name=="fathername")//这里对你来说应该是form2
{
childrenform.visible
=
true;//如果你要求关闭的话就只要close就可以了,我现在是如果存在就显示,你可以参考一下,你也可以不
childrenform.activate();
isopen
=
true;
return;
}
}
if
(!isopen)
{
frmsetproduct
productset
=
new
frmsetproduct();
productset.mdiparent
=
this;
productset.windowstate
=
formwindowstate.maximized;
productset.show();
}
}
相似回答