C#winform判断子窗口是否已关闭或在关闭的时候触发事件15
发布网友
发布时间:2024-02-24 02:02
我来回答
共4个回答
热心网友
时间:2024-03-31 02:45
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事件,既然关闭了窗体,那相关进程也要关掉。免得一直占用内存资源。
热心网友
时间:2024-03-31 02:45
关于窗口关闭事件有两个,一个是关闭后的closed和关闭中的closing!前者应该可以实现子窗体关闭向父窗体发送或设置一个值作为窗口关闭的通知,后者通常是用来做个关闭询问的功能,可取消窗口关闭
热心网友
时间:2024-03-31 02:46
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事件,既然关闭了窗体,那相关进程也要关掉。免得一直占用内存资源。
热心网友
时间:2024-03-31 02:47
不需要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)
{
frmsetproct
proctset
=
new
frmsetproct();
proctset.mdiparent
=
this;
proctset.windowstate
=
formwindowstate.maximized;
proctset.show();
}
}