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事件,既然关闭了窗体,那相关进程也要关掉。免得一直占用内存资源。
{
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事件,既然关闭了窗体,那相关进程也要关掉。免得一直占用内存资源。
展开全部
关于窗口关闭事件有两个,一个是关闭后的closed和关闭中的closing!前者应该可以实现子窗体关闭向父窗体发送或设置一个值作为窗口关闭的通知,后者通常是用来做个关闭询问的功能,可取消窗口关闭
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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事件,既然关闭了窗体,那相关进程也要关掉。免得一直占用内存资源。
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事件,既然关闭了窗体,那相关进程也要关掉。免得一直占用内存资源。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不需要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();
}
}
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();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询