第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();
}
}