C# FormClosing!!!

yoyo83773 2010-01-16 07:56:07
A NEW 出B ,然后A隐藏,B 上关闭想弹出确认框,“确定”的话结束进程,否则不变化!确定两次怎么解决!而且 弄成确定一次的了,但进程没有结束!
...全文
415 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
szxuzheng 2011-11-25
  • 打赏
  • 举报
回复
把 Application.Exit();写在FormClosed事件即可!
--------------------------------------------------------------------------
private void frmAdminMain_FormClosed(object sender, FormClosedEventArgs e)
{
DialogResult dr = MessageBox.Show("确认退出?", "标题", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
if (dr == DialogResult.OK)
{
Application.Exit();
}
else
{
frmAdminMain fa = new frmAdminMain();
fa.Show();
}

}
烈火蜓蜻 2010-01-16
  • 打赏
  • 举报
回复
private void button1_Click(object sender, EventArgs e)
{
B fm = new B();
fm.FormClosing += A_FormClosing;
this.FormClosing += A_FormClosing;
fm.Show();
this.Hide();
}
private void A_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("确认关闭?", "退出", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
Application.Exit();
}
else
e.Cancel = true;
}

B窗体代码不用写任何关于确定关闭的代码


不用写那么多代码
ysz89757 2010-01-16
  • 打赏
  • 举报
回复
这个问题经常有人问
mngzilin 2010-01-16
  • 打赏
  • 举报
回复
form1中:
private void button1_Click(object sender, EventArgs e)
{
Form2 fm = new Form2();
fm.Owner = this;
fm.Show();
this.Hide();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("确认关闭?", "退出", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
e.Cancel = false;
}
else
e.Cancel = true;
}

form2中:
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("确认关闭?", "退出", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
e.Cancel = false;
this.Owner.Show();
}
else
e.Cancel = true;
}
初见·冬雪 2010-01-16
  • 打赏
  • 举报
回复
学习
pos老吴 2010-01-16
  • 打赏
  • 举报
回复
学习
wuyq11 2010-01-16
  • 打赏
  • 举报
回复
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{

if (MessageBox.Show("确定退出", "提示",MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.Cancel)
{
e.Cancel = true;
}
}
Application.Exit() 停止在所有线程上运行的所有消息循环,并关闭应用程序的所有窗口

111,121

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧