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

怎么样判断C#winform怎么判断窗口是否已经关闭或在关闭窗口的时候可以触发一个什么事件。... 怎么样判断C#winform怎么判断窗口是否已经关闭或在关闭窗口的时候可以触发一个什么事件。 展开
 我来答
樱桃花花孩子
推荐于2018-05-10 · 超过52用户采纳过TA的回答
知道答主
回答量:128
采纳率:0%
帮助的人:0
展开全部
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事件,既然关闭了窗体,那相关进程也要关掉。免得一直占用内存资源。
认真还挺拔灬仙人掌H
2010-05-29 · TA获得超过108个赞
知道答主
回答量:69
采纳率:0%
帮助的人:67.5万
展开全部
关于窗口关闭事件有两个,一个是关闭后的closed和关闭中的closing!前者应该可以实现子窗体关闭向父窗体发送或设置一个值作为窗口关闭的通知,后者通常是用来做个关闭询问的功能,可取消窗口关闭
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
花昊佟向露
2020-05-25 · TA获得超过3683个赞
知道大有可为答主
回答量:3087
采纳率:29%
帮助的人:422万
展开全部
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事件,既然关闭了窗体,那相关进程也要关掉。免得一直占用内存资源。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
腾昌休秋芸
2020-02-25 · TA获得超过3794个赞
知道大有可为答主
回答量:3142
采纳率:31%
帮助的人:235万
展开全部
不需要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();
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式