如何在我的应用程序中制作(默认)关闭 按钮(位于右上角),以将其用作最小化。 实际上我想在点击十字符号时最小化应用程序,但是当使用点击我的菜单选项退出时退出应用程序。
我写了这段代码来最小化点击关闭按钮时的表单:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (minimize_on_close == "Yes")
{
e.Cancel = true;
this.WindowState = FormWindowState.Minimized;
}
}
并编写了这段代码,用于在单击菜单选项中的退出时退出应用程序。
private void exitToolStripMenuItem1_Click(object sender, EventArgs e)
{
Application.Exit();
}
但是现在,当我点击退出菜单选项时,表单也会被最小化,而不是退出。
有人可以帮忙吗?
最佳答案
查看是否FormClosingEventArgs.CloseReason
在决定最小化窗口之前等于 CloseReason.UserClosing
。或者,比较 CloseReason.ApplicationExitCall
。
来自 CloseReason
的文档:
Members
...
UserClosing
The user is closing the form through the user interface (UI), for example by clicking the Close button on the form window, selecting Close from the window's control menu, or pressing ALT+F4.
...
ApplicationExitCall
The Exit method of the Application class was invoked.
关于c# - 如何使关闭按钮像最小化一样工作 : C# Winforms,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15459105/