[英]Don't want to exit program when user click on Close button in titlebar of C# app
从事C#应用程序的开发。
我想在标题栏中保持“关闭”按钮在右上角,但是如果最终用户单击它,我所希望的就是他获得了一个信息窗口,他无法关闭应用程序,除非其他适当的按钮。
有可能实现吗?
广告中的Tnx!
将事件处理程序添加到窗体的OnClosing
事件。 事件参数包含元素Cancel
。 将其设置为true
不会关闭。
本质上是这样的:
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = !stuffdone;
}
您可以像这样处理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.