C# 表单关闭时的操作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2261179/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Action when form is closed
提问by Saska
How to make as by pressing to the close button, make so that the form was not closed, and it was turned off?
如何通过按下关闭按钮使表单不被关闭,而是被关闭?
private void Form1_Closed(object sender, EventArgs e)
{
Form1.Hide();
}
So the form is all the same closed.
所以形式都是一样的封闭。
采纳答案by MadBoy
You should do it on FormClosing not FormClosed event like this:
你应该在 FormClosing 而不是 FormClosed 事件上这样做:
private void Form1_FormClosing(object sender, EventArgs e) {
Form1.Hide();
e.Cancel = true;
}
FormClosed means the form is already closed.
FormClosed 表示表单已经关闭。
回答by Bobby
Use the FormClosing
event, and set e.Cancel
to true.
使用FormClosing
事件,并设置e.Cancel
为true。
回答by Nick Craver
You want to interrupt the form closing event and cancel it, for example to minimize:
您想中断表单关闭事件并取消它,例如最小化:
private void Form_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
this.WindowState = FormWindowState.Minimized;
}
回答by Asad
Here is the sample. you have several options
这是示例。你有几个选择
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
// this.Hide();
// e.Cancel = true;
this.Close();
}
to remove a form both from the display, and from memory, it is necessary to Close rather than Hide it
要从显示和内存中删除表单,必须关闭而不是隐藏它