[英]Don't want to exit program when user click on Close button in titlebar of C# app
Working on development of C# application. 从事C#应用程序的开发。
I want to keep Close button on top right in title bar, but if end users click on it, all I want is that he gets info window that he can not close application until some other proper button. 我想在标题栏中保持“关闭”按钮在右上角,但是如果最终用户单击它,我所希望的就是他获得了一个信息窗口,他无法关闭应用程序,除非其他适当的按钮。
Is it possible to achieve? 有可能实现吗?
Tnx in adv! 广告中的Tnx!
Add an event handler to the OnClosing
event of the form. 将事件处理程序添加到窗体的OnClosing
事件。 The event argument contains an element Cancel
. 事件参数包含元素Cancel
。 Set it to true
and it won't close. 将其设置为true
不会关闭。
Essentially something like this: 本质上是这样的:
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = !stuffdone;
}
You can handle the FormClosing
event event handler like this 您可以像这样处理FormClosing
事件事件处理程序
private void Form_FormClosing(object sender, FormClosingEventArgs e)
{
//there can be other reasons for form close make sure X button is clicked
// if close button clicked
if (e.CloseReason == CloseReason.UserClosing)
{
e.Cancel = true;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.